为什么我的`ExifInterfae`没有显示属性?

时间:2015-07-13 16:07:46

标签: android

我有以下代码:

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();
}

它应该在UserComment result.getCaptureTime()下从相机捕获它。我将它下载到Windows文件夹,我看不到我刚刚创建的属性...

我做错了什么?

修改

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();
        }
    }

0 个答案:

没有答案