How to write Exif Data using custom camera class in Android?

I have a custom camera application that is used to shoot and crop them into a square, now I want to know how to write Exif data for the final output image (especially for orientation)

Here are the important parts of my code:

captureButton = (Button) findViewById(R.id.button_capture); captureButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // Take a picture mCamera.takePicture(null, null, mPicture); } }); 

and this is the callback function:

 PictureCallback mPicture = new PictureCallback() { @Override public void onPictureTaken(byte[] data, Camera camera) { File pictureFile = getOutputMediaFile(); if (pictureFile == null) { return; } try { FileOutputStream fos = new FileOutputStream(pictureFile); fos.write(data); fos.close(); } catch (FileNotFoundException e) { } catch (IOException e) { } } }; 

Update: I added the following to the onPictureTaken method, but nothing changed:

 ExifInterface exif; exif = new ExifInterface(pictureFile.getAbsolutePath()); // Notice getOrientation method gets an Integer with the angle : 0 , 90 , 180 , 270 ..etc exif.setAttribute(ExifInterface.TAG_ORIENTATION, String.valueOf(getOrientation()) ); exif.saveAttributes(); 
+8
android android camera
source share
1 answer

I know this is old, but I had a similar problem, so I thought I would make up for it first. If they understand that you are trying to save the angle in the exif.TAG_ORIENTATION attribute. This is not true. Adjust the getOrientation method to give you one of the following orientation constants related to the ExifInterface class.

By placing a specific angle, exif data will not be correctly read using Image Viewers and how I read your question, what are you doing.

int ORIENTATION_FLIP_HORIZONTAL int ORIENTATION_FLIP_VERTICAL
int ORIENTATION_NORMAL int ORIENTATION_ROTATE_180
int ORIENTATION_ROTATE_270 int ORIENTATION_ROTATE_90
int ORIENTATION_TRANSPOSE int ORIENTATION_TRANSVERSE
int ORIENTATION_UNDEFINED

0
source share

All Articles