0

I have the following code:

YuvImage yuv = new YuvImage(result.getExtractImageData(), 
        camera.getParameters().getPreviewFormat(),
        result.getWidth(), 
        result.getHeight(), null);

ByteArrayOutputStream out = new ByteArrayOutputStream();
yuv.compressToJpeg(new Rect(0, 0, result.getWidth(), result.getHeight()), 100, out);

byte[] bytes = out.toByteArray();

Bitmap image = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);

image = RotateImage(image, rotation);

createDirectoryAndSaveFile(image, "Image_" + result.getCaptureTime() + ".jpg");

String filePath = Environment.getExternalStorageDirectory() + "/MyFolder/Image_" + result.getCaptureTime() + ".jpg";
try {
    ExifInterface exif = new ExifInterface(filePath);
    exif.getAttribute("UserComment");

    // call this next setAttributes a few times to write all the GPS data to it.
    exif.setAttribute("UserComment", String.valueOf(result.getCaptureTime()));
    exif.saveAttributes();
} 
catch (IOException e) {
    e.printStackTrace();
}

It is supposed to punt under UserComment the result.getCaptureTime() at which it was captured from the camera. I download it to a Windows folder and I can't see the properties I just created...

What I'm doing wrong?

EDIT:

private void createDirectoryAndSaveFile(Bitmap imageToSave, String fileName)           
{
        File direct = new File(Environment.getExternalStorageDirectory() + "/MyFolder");

        if (!direct.exists()) {
            File wallpaperDirectory = new File("/sdcard/MyFolder/");
            wallpaperDirectory.mkdirs();
        }

        File file = new File(new File("/sdcard/MyFolder/"), fileName);
        if (file.exists()) {
            file.delete();
        }
        try {
            FileOutputStream out = new FileOutputStream(file);
            imageToSave.compress(Bitmap.CompressFormat.JPEG, 100, out);
            out.flush();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
Sonhja
  • 8,230
  • 20
  • 73
  • 131
  • To begin with: What is 'result'? – greenapps Jul 13 '15 at 16:13
  • 'createDirectoryAndSaveFile(image, "Image_" + result.getCaptureTime() + ".jpg");' Well you are saving a bitmap 'image' to file. Where is the code? Are you saving a bitmap or do you convert to .jpg? – greenapps Jul 13 '15 at 16:17
  • 'catch (IOException e) '. Do you have a catch? How do you know? – greenapps Jul 13 '15 at 16:19
  • Hard to explain what's `result`... It contains information about the recently captured image. I forgot to post the `createDirectoryAndSaveFile`. Sorry... – Sonhja Jul 13 '15 at 16:22
  • I have a catch, but it never happens (I debugged, of course...) – Sonhja Jul 13 '15 at 16:22
  • Your newly added function works with three paths and the final path does not match with the one you use later. A mess. – greenapps Jul 13 '15 at 16:28
  • I made a mistake with folder name. Don't be ofensive, please. I'm always respectful. – Sonhja Jul 13 '15 at 16:30
  • That code comes from here: http://stackoverflow.com/a/20369870/760893 – Sonhja Jul 13 '15 at 16:30
  • 'exif.saveAttributes()'. Does that really save to file? Please tell what the file length is before and after this statement. By the way: Why are you reading exif info from that file? There will not be any exif info in your newly created file. – greenapps Jul 13 '15 at 16:31
  • That's what I don't know and I haven't read that anywhere. I just want to add ExifInfo to my image... The debug doesn't break there, that's why I suppose it's being saved. – Sonhja Jul 13 '15 at 16:33
  • With all my respect too: I see `MyFolder` everywhere... For me that part is working, and my main question is not that, my main question is: `how to add exif info to my image`, but no answer. So now that I see that this thread is being ignored because so much unhelpful comments, only critiques, I will close it. Thank you. – Sonhja Jul 14 '15 at 07:21

0 Answers0