【发布时间】:2015-07-14 16:31:41
【问题描述】:
我只是在 Android 应用程序上创建来自相机的图像:
YuvImage yuv = new YuvImage(
byteArrayDataFromCamera,
camera.getParameters().getPreviewFormat(),
imageWidth,
imageHeight, null);
ByteArrayOutputStream out = new ByteArrayOutputStream();
yuv.compressToJpeg(new Rect(0, 0, imageWidth, imageHeight, 100, out);
byte[] bytes = out.toByteArray();
Bitmap image = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
我想在其中添加Exif information。从现在开始我已经尝试过:
// Save image on SD
storeImage(image, "Image_0.jpg");
String filePath = Environment.getExternalStorageDirectory() + "/MyFolder/Image_0.jpg";
try {
ExifInterface exif = new ExifInterface(filePath);
exif.setAttribute("UserComment", "my custom comment");
exif.saveAttributes();
}
catch (IOException e) {
e.printStackTrace();
}
storeImage 方法:
private boolean storeImage(Bitmap imageData, String filename) {
//get path to external storage (SD card)
String iconsStoragePath = Environment.getExternalStorageDirectory() + "/MyFolder/";
File sdIconStorageDir = new File(iconsStoragePath);
//create storage directories, if they don't exist
sdIconStorageDir.mkdirs();
try {
String filePath = sdIconStorageDir.toString() + filename;
FileOutputStream fileOutputStream = new FileOutputStream(filePath);
BufferedOutputStream bos = new BufferedOutputStream(fileOutputStream);
//choose another format if PNG doesn't suit you
imageData.compress(CompressFormat.PNG, 100, bos);
bos.flush();
bos.close();
} catch (FileNotFoundException e) {
Log.w("TAG", "Error saving image file: " + e.getMessage());
return false;
} catch (IOException e) {
Log.w("TAG", "Error saving image file: " + e.getMessage());
return false;
}
return true;
}
由于我的图像是最近创建的,它没有任何ExifInterface 信息。我想知道如何将新的ExifInterface 添加到我最近创建的图像中。如何做到这一点?
【问题讨论】:
-
你想在图片信息中添加什么?是否可以轮换?还是只评论?
-
是的,对不起。只有一个自定义字符串,其中包含每个图像的一些特定信息。
-
@Sonhja 你现在可以阅读我编辑的帖子......告诉我这个消息!好编程!!
-
@MerlíPérezEscarpenter 是的,正在阅读。我会让你知道它是否有效。看起来不错的答案。我会尽力让你知道!
标签: android