I used www.jcgonzalez.com/img/0/75/libraries.zip this libraries and here is my code
public static void pdfconverter(String FILEPATH){
Document document = new Document();
try {
document.setFile(FILEPATH);
} catch (PDFException ex) {
System.out.println("Error parsing PDF document " + ex);
} catch (PDFSecurityException ex) {
System.out.println("Error encryption not supported " + ex);
} catch (FileNotFoundException ex) {
System.out.println("Error file not found " + ex);
} catch (IOException ex) {
System.out.println("Error IOException " + ex);
}
float scale = 1.0f;
float rotation = 0f;
for (int i = 0; i < document.getNumberOfPages(); i++) {
BufferedImage image = (BufferedImage) document.getPageImage(
i, GraphicsRenderingHints.PRINT, Page.BOUNDARY_CROPBOX, rotation, scale);
RenderedImage rendImage = image;
try {
System.out.println(" capturing page " + i);
File file = new File("imageCapture1_" + i + ".tif");
ImageIO.write(rendImage, "tiff", file);
} catch (IOException e) {
e.printStackTrace();
}
image.flush();
}
document.dispose();
}
But the image shows square instead of 'ş'. Any idea why?
Related
`# Dears, this class works well to receive PDF files from another application on below Android 6, but it gives an error for Android uper 6
` #RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public int ExtractImage(Intent intent) {
try {
String filepath = null;
if (intent != null) {
String action = intent.getAction();
String type = intent.getType();
if (Intent.ACTION_VIEW.equals(action) && type.endsWith("pdf")) {
Uri file_uri = intent.getData();
if (file_uri != null) {
filepath = file_uri.getPath();
}
} else if (Intent.ACTION_SEND.equals(action) && type.endsWith("pdf")) {
Uri uri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
if (uri != null) {
filepath = uri.getPath();
}
}
}
File file = new File(filepath);
PdfRenderer renderer = null;
Bitmap bm;
try {
renderer = new PdfRenderer(ParcelFileDescriptor.open(file,
ParcelFileDescriptor.MODE_READ_ONLY));
} catch (Exception e) {
}
assert renderer != null;
final int pageCount = renderer.getPageCount();
totalPage = pageCount;
for (int i = 0; i < pageCount; i++) {
PdfRenderer.Page page = renderer.openPage(i);
// Create a bitmap and canvas to draw the page into
int width = 570;
int zarib = 570 / (page.getWidth() + 1);
int height = (page.getHeight() * 2) + 1;
heightArray.add(i, height);
// Create a bitmap and canvas to draw the page into
bm = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
// Create canvas to draw into the bitmap
Canvas c = new Canvas(bm);
// Fill the bitmap with a white background
Paint whiteBgnd = new Paint();
whiteBgnd.setColor(Color.WHITE);
whiteBgnd.setStyle(Paint.Style.FILL);
c.drawRect(0, 0, width, height, whiteBgnd);
// paint the page into the canvas
page.render(bm, null, null, PdfRenderer.Page.RENDER_MODE_FOR_PRINT);
// Save the bitmap
OutputStream outStream = null;
try {
outStream = new
FileOutputStream(Environment.getExternalStorageDirectory().getAbsolutePath()
+ "/printDo2ta" + i + ".png");
} catch (Exception e) {
e.printStackTrace();
}
bm.compress(Bitmap.CompressFormat.PNG, 80, outStream);
try {
outStream.close();
} catch (Exception e) {
e.printStackTrace();
}
page.close();
}
} catch (Exception e) {
runOnUiThread(() -> Toast.makeText(getBaseContext(),
"خطا در پردازش فایل: " + e.getMessage(),
Toast.LENGTH_SHORT).show());
}
return totalPage;
}
I inserted this code in AndroidManifest.xml
`<provider
android:name="androidx.core.content.FileProvider"
android:authorities="ir.myproject.test.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/provider_paths" />
</provider>`
`
And I made the class provider_paths.xml
`<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-path name="external_files" path="."/>
</paths>`
I don't know what else I need to change to make it work on Android 8
please help me`
I'm using EmguCV 3.4. I need to store snapshots from IP camera periodically(5 mins). I try to stored snapshots in the Content folder (ASP.NET MVC). I got access violation exception. Help me.
My Code,
private VideoCapture _capture = null;
private Mat _frame;
public void GetSnapshot(CameraDTO cameraDTO)
{
CvInvoke.UseOpenCL = false;
try
{
_capture = new VideoCapture(cameraDTO.CameraAccessURL);
_capture.ImageGrabbed += ProcessFrame;
if (StartCapture())
{
while (_frame == null)
{
//wait untill camera ready
}
if (_frame != null && _capture != null)
{
Image<Bgr, Byte> imgeOrigenal = _frame.ToImage<Bgr, Byte>();
imgeOrigenal.Save(#ImageSavepath + #"\ImageFromCamera" + cameraDTO.camID + ".jpg");
}
}
}
catch (Exception excpt)
{
Console.WriteLine(excpt.Message);
}
}
private bool StartCapture()
{
if (_capture != null)
{
_capture.Start();
return true;
}
return false;
}
private void ProcessFrame(object sender, EventArgs e)
{
try
{
if (_capture != null && _capture.IsOpened && _capture.Ptr != IntPtr.Zero && _frame != null)
{
_frame = new Mat();
_capture.Retrieve(_frame, 0);
}
}
catch (AccessViolationException exv)
{
Console.WriteLine("ERROR: {0}", exv.Message);
return;
}
catch (Exception ex)
{
Console.WriteLine("ERROR: {0}", ex.Message);
return;
}
}
#ImageSavepath = Content folder, randomly generate the issue
The problem is that you use _frame in another thread (cross-thread manipulating). You should save the image inside FrameProcess().
private void FrameProcess(object sender, EventArgs e)
{
try
{
if (_capture != null && _capture.IsOpened && _capture.Ptr != IntPtr.Zero && _frame != null)
{
_frame = new Mat();
_capture.Retrieve(_frame, 0);
Image<Bgr, Byte> imgeOrigenal = _frame.ToImage<Bgr, Byte>();
imgeOrigenal.Save(#ImageSavepath + #"\ImageFromCamera" + cameraDTO.camID + ".jpg");
}
}
catch (AccessViolationException exv)
{
Console.WriteLine("ERROR: {0}", exv.Message);
return;
}
catch (Exception ex)
{
Console.WriteLine("ERROR: {0}", ex.Message);
return;
}
}
I get my position in EPSG: 4326 by my Android GPS, now i would convert it coordinates to EPSG: 32632.
Someone have an idea?
Use geotools.
http://www.geotools.org/
Here is an transformation example.
http://docs.geotools.org/stable/userguide/library/api/jts.html
First, you have to remove 3 jar files from the download directory as follows:
For example geotools version 18.0,
gt-epsg-hsql-18.0.jar gt-epsg-oracle-18.0.jar
gt-epsg-postgresql-18.0.jar
There are almost two cases existing.
1. using decode method of a CRS class:
CRSFactory crsFactory = ReferencingFactoryFinder.getCRSFactory(null);
CoordinateReferenceSystem targetCRS = null;
CoordinateReferenceSystem sourceCRS = null;
Geometry transCoordGeometry = null;
try {
targetCRS = CRS.decode("EPSG:32632");
sourceCRS = CRS.decode("EPSG:4326");
} catch (FactoryException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
MathTransform transform = null;
try {
transform = CRS.findMathTransform(sourceCRS, targetCRS);
transCoordGeometry = JTS.transform(orgGeometry, transform);
} catch (FactoryException | MismatchedDimensionException | TransformException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Using a wkt string.
the string variable of the targetWKT from
http://spatialreference.org/ref/epsg/wgs-84-utm-zone-32n/prettywkt/
PROJCS["WGS 84 / UTM zone 32N",
GEOGCS["WGS 84",
DATUM["WGS_1984",
SPHEROID["WGS 84",6378137,298.257223563,
AUTHORITY["EPSG","7030"]],
AUTHORITY["EPSG","6326"]],
PRIMEM["Greenwich",0,
AUTHORITY["EPSG","8901"]],
UNIT["degree",0.01745329251994328,
AUTHORITY["EPSG","9122"]],
AUTHORITY["EPSG","4326"]],
UNIT["metre",1,
AUTHORITY["EPSG","9001"]],
PROJECTION["Transverse_Mercator"],
PARAMETER["latitude_of_origin",0],
PARAMETER["central_meridian",9],
PARAMETER["scale_factor",0.9996],
PARAMETER["false_easting",500000],
PARAMETER["false_northing",0],
AUTHORITY["EPSG","32632"],
AXIS["Easting",EAST],
AXIS["Northing",NORTH]]
Then, the code is:
CRSFactory crsFactory = ReferencingFactoryFinder.getCRSFactory(null);
CoordinateReferenceSystem targetCRS = null;
CoordinateReferenceSystem sourceCRS = null;
Geometry transCoordGeometry = null;
try {
targetCRS = crsFactory.createFromWKT(targetWKT);
sourceCRS = CRS.decode("EPSG:4326");
} catch (FactoryException e1) {
e1.printStackTrace();
}
MathTransform transform = null;
try {
transform = CRS.findMathTransform(sourceCRS, targetCRS);
transCoordGeometry = JTS.transform(orgGeometry, transform);
} catch (FactoryException | MismatchedDimensionException | TransformException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
I have set up an Android camera application that allows me to preview the camera in a Frame Layout within my main Activity. What I would like to do (without using camera specific functionality; I want this to be completely independent of hardware.) is out line 150 X 150 pixels in the center of the preview either by showing a box around the pixels or blurring all of the pixels except the 150 x 150. Additionally, without taking a picture, I would like to read these pixels. Ultimately the effect I am going for is, as the camera is moved I display the change in the red, green, and blue color concentrations within the 150 x 150 area. I know how to do the nested for loop and get the color from the pixel, but I would need to know how to get the offset for the height and weight to start reading the pixels from.
Thanks in advance for all of your help!
Mike
public class MyActivity extends Activity {
final public String TAG = "MyActivity";
static private Camera mCamera = null;
static public Camera getCamera() { return mCamera; }
private static boolean mBPreviewingCamera = false;
private PreviewSurface mPS;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String lMTH = "onCreate ";
Log.i(TAG, lMTH + "Start");
setContentView(R.layout.activity_color_temperature_estimator);
if (isThereACamera()) {
mPreviewCamera(true);
TextView lTVTemp = (TextView) findViewById(R.id.TV_TEMP);
lTVTemp.setText("Camera exists able to proceed");
lTVTemp = null;
} else {
Toast.makeText(this, "No camera! Uunable to proceed", Toast.LENGTH_LONG).show();
TextView lTVTemp = (TextView) findViewById(R.id.TV_TEMP);
lTVTemp.setText("No camera! Uunable to proceed");
lTVTemp = null;
}
}
public void mPreviewCamera(boolean pBPreviewingCamera) {
String lMTH = "mPreviewCamera ";
try {
if (pBPreviewingCamera) {
Log.i(TAG, lMTH + "Open Camera");
mCamera = Camera.open();
mPS = new PreviewSurface(this);
FrameLayout lFVPreview = (FrameLayout) findViewById(R.id.FL_Preview);
lFVPreview.addView(mPS);
lFVPreview = null;
mBPreviewingCamera = true;
Button lBTNTemp = (Button) findViewById(R.id.BTN_CLOSE);
lBTNTemp.setText(R.string.BTN_CLOSE);
lBTNTemp = null;
} else {
Log.i(TAG, lMTH + "Open Camera");
mCloseCamera();
Button lBTNTemp = (Button) findViewById(R.id.BTN_CLOSE);
lBTNTemp.setText(R.string.BTN_OPEN);
lBTNTemp = null;
}
} catch (Exception e) {
Log.i(TAG, lMTH + e.getMessage());
mCloseCamera();
e.printStackTrace();
}
}
public void mCloseCamera() {
String lMTH = "mCloseCamera ";
Log.i(TAG, lMTH + "Turn Camera Off");
if (mCamera != null) {
mCamera.stopPreview();
mCamera.release();
}
mCamera = null;
mBPreviewingCamera = false;
}
#Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
String lMTH = "onPause ";
Log.i(TAG, lMTH + "Turn Camera Off");
mPreviewCamera(false);
}
#Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
String lMTH = "onDestroy ";
Log.i(TAG, lMTH + "Turn Camera Off");
mPreviewCamera(false);
}
/** Check if this phone has a camera */
private boolean isThereACamera() {
if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA)){
// There is a camera
return true;
} else {
// There isn't a camera
return false;
}
}
public void mBTN(View view) {
mPreviewCamera(!mBPreviewingCamera);
}
}
public class PreviewSurface extends SurfaceView implements SurfaceHolder.Callback {
final static public String TAG = "PreviewSurface";
private SurfaceHolder mSH;
/**
* #param context
*/
public PreviewSurface(Context pContext) {
super(pContext);
// TODO Auto-generated constructor stub
String lMTH = "PreviewSurface(Context pContext) ";
Log.i(TAG, lMTH + "Constructor");
pContext = null;
mSH = getHolder();
mSH.addCallback(this);
mSH.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
/* (non-Javadoc)
* #see android.view.SurfaceHolder.Callback#surfaceChanged(android.view.SurfaceHolder, int, int, int)
*/
public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
String lMTH = "surfaceChanged ";
// TODO Auto-generated method stub
Log.i(TAG, lMTH + "arg1 = " + arg1 + " arg2 " + arg2 + " arg3 " + arg3);
if (arg0.getSurface() != null) {
// stop old preview if it exists
try {
Log.i(TAG, lMTH + "Stop Preview ");
MyActivity.getCamera().stopPreview();
} catch (Exception e) {
Log.i(TAG, lMTH + "Stoping preview exception " + e.getMessage());
}
// start new preview
try {
Log.i(TAG, lMTH + "Set Preview ");
MyActivity.getCamera().setPreviewDisplay(arg0);
Log.i(TAG, lMTH + "Start Preview ");
MyActivity.getCamera().startPreview();
} catch (Exception e){
Log.i(TAG, lMTH + "Starting camera preview exception " + e.getMessage());
}
}
// stop preview before making changes
}
/* (non-Javadoc)
* #see android.view.SurfaceHolder.Callback#surfaceCreated(android.view.SurfaceHolder)
*/
public void surfaceCreated(SurfaceHolder arg0) {
String lMTH = "surfaceCreated ";
// TODO Auto-generated method stub
try {
Log.i(TAG, lMTH + "Set Preview ");
MyActivity.getCamera().setPreviewDisplay(arg0);
Log.i(TAG, lMTH + "Start Preview ");
MyActivity.getCamera().startPreview();
} catch (Exception e) {
Log.i(TAG, lMTH + "Exception " + e.getMessage());
e.printStackTrace();
}
}
/* (non-Javadoc)
* #see android.view.SurfaceHolder.Callback#surfaceDestroyed(android.view.SurfaceHolder)
*/
public void surfaceDestroyed(SurfaceHolder arg0) {
String lMTH = "surfaceDestroyed ";
// TODO Auto-generated method stub
Log.i(TAG, lMTH + "Activity will handle destroy");
}
"I would need to know how to get the offset for the height and weight
to start reading the pixels from"
An easy way to get the offset for your nested for-loop is walked through with descriptive variables:
int xWidth = 150; // The length you want to concentrate on
int yHeight = 150;
int xCenter = previewWidth/2;
int yCenter = previewHeight/2;
int xStart = xCenter - xWidth/2;
int xEnd = xCenter + xWidth/2;
int yStart = yCenter - yHeight/2;
int yEnd = yCenter + yHeight/2;
for(int y = yStart; y < yEnd; y++) {
for(int x = xStart; x < xEnd; x++) {
// read pixels
}
}
The previewWidth and previewHeight can be easily gotten from surfaceChange():
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
previewWidth = w;
previewHeight = h;
...
}
The reason I use many variables here is so that you can clearly see how I walked through this problem.
Let me know how it goes.
i am saving an image by passing a bitmap to the savephoto(Bitmap function)
now i want to retrieve the photo which is saved ,, how to do that i am new in android , plz give me the code of retrival and also convert it into Bitmap
public void savePhoto(Bitmap b2)
{
File imageFileFolder = new File(Environment.getExternalStorageDirectory(),"Rotate");
mageFileFolder.mkdir();
FileOutputStream out = null;
Calendar c = Calendar.getInstance();
String date = fromInt(c.get(Calendar.MONTH))
+ fromInt(c.get(Calendar.DAY_OF_MONTH))
+ fromInt(c.get(Calendar.YEAR))
+ fromInt(c.get(Calendar.HOUR_OF_DAY))
+ fromInt(c.get(Calendar.MINUTE))
+ fromInt(c.get(Calendar.SECOND));
File imageFileName = new File(imageFileFolder, date.toString() + ".jpg");
try
{
out = new FileOutputStream(imageFileName);
b2.compress(Bitmap.CompressFormat.JPEG, 100, out);
out.flush();
out.close();
out = null;
} catch (Exception e)
{
e.printStackTrace();
}
thanx helping :)