0

I save image from custom camera:

public String getFilename() { File file = new File(Environment.getExternalStorageDirectory().getPath(), "Products/Images"); if (!file.exists()) { file.mkdirs(); } String uriSting = (file.getAbsolutePath() + "/" + System.currentTimeMillis() + ".jpg"); return uriSting; } 

Now:

public String saveImage(Bitmap bitmap) { FileOutputStream out = null; String filename = getFilename(); try { out = new FileOutputStream(filename); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out); } catch (FileNotFoundException e) { Log.e("Error",e.toString()); e.printStackTrace(); return ""; } return filename; } 

I use this filename in exifInterface after saving image

exif = new ExifInterface(filePath); 

But every time it shows in my log Raw image not detected, Exif: 0

1
  • file.mkdirs(); Adapt your code. Check the return value of mkdirs an stop if false. Return null. Stop and display a toast to inform the user. Commented Nov 16, 2020 at 8:46

2 Answers 2

1

You compress a bitmap to a jpg file.

Bitmaps dont contain exif information.

And compressing a bitmap to a jpg file does not add an exif header to the file.

Sign up to request clarification or add additional context in comments.

6 Comments

can you tell me other way to get the image because I use this when I capture BitmapFactory.decodeByteArray(data, 0, data.length); , this will give a bitmap , how can I get something which contains exif information
FileOutputStream , seems to be the choice then
???? You constructed your bitmap from 'data'. So what exactly was in data?
I will accept your answer once my query is resolved thanks a lot !
You accepted the wrong answer. Well.. not that it was wrong...
|
0

BitmapFactory.decodeByteArray(data, 0, data.length);

You have a nice byte array called data.

This byte array contains the bytes of a jpg file with exif header.

If you wanna save the data to file then do not make an intermediate bitmap first as at that moment you lost the exif header.

Instead save the bytes in your data array directly to file.

Then you will have a jpg file with an exif header.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.