我只是在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
。怎么能实现这个目标?
答案 0 :(得分:1)
我知道您可以在图片信息中添加轮播,但添加评论会更复杂。 Exif类无法正常工作...因为您可以从流中读取Exif信息,但您可以编写此信息。当我搜索信息以添加图像信息时,用户遇到与您相同的问题,并且我知道现有的库可以在图像信息中添加信息... 当我找到帖子时,我会给你一个URL !!
我可以找到帖子,阅读Pattern documentation !!
告诉我,如果我帮助你并做好编程!