gpt4 book ai didi

android - 将元数据添加到 Android 中创建的位图中

转载 作者:行者123 更新时间:2023-11-30 02:53:16 27 4
gpt4 key购买 nike

我正在使用相机 Intent 拍照,然后将该图像转换为字节数组并最终将其保存在本地数据库中。用相机拍摄的原始图像具有所有元数据,如 GPS 纬度和经度等。但是,我从该图像创建的位图不包含任何元数据。如何将原始元数据添加到我的图像中?

这是我的相机 Intent 返回的代码:

picUri = data.getData()    
Bitmap yourSelectedImage62 = null;
String imagebytes2 ;
try
{
yourSelectedImage62 = MediaStore.Images.Media.getBitmap(this.getContentResolver(), picUri);
yourSelectedImage62 = Bitmap.createScaledBitmap(yourSelectedImage62, large_width, large_height, true);
} catch (FileNotFoundException ex)
{
Logger.getLogger(Screen_View_Submission.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(Screen_New_Submission.class.getName()).log(Level.SEVERE, null, ex);
}

ByteArrayOutputStream bao62 = new ByteArrayOutputStream();
yourSelectedImage62.compress(Bitmap.CompressFormat.JPEG, 75, bao62);
byte[] ba62 = bao62.toByteArray();
imagebytes2 = Base64.encodeToString(ba62,Base64.DEFAULT);
yourSelectedImage62.recycle();

最佳答案

元数据不是位图的属性。它存储为 JPEG 文件的 Exinf。使用 ExifInterface此处更新元数据是设置 gps 坐标的示例

exif = new ExifInterface(imageFile.getAbsolutePath());
int num1Lat = (int) Math.floor(latitude);
int num2Lat = (int) Math.floor((latitude - num1Lat) * 60);
double num3Lat = (latitude - ((double) num1Lat + ((double) num2Lat / 60))) * 3600000;

int num1Lon = (int) Math.floor(longitude);
int num2Lon = (int) Math.floor((longitude - num1Lon) * 60);
double num3Lon = (longitude - ((double) num1Lon + ((double) num2Lon / 60))) * 3600000;

exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE, num1Lat + "/1," + num2Lat + "/1," + num3Lat + "/1000");
exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE, num1Lon + "/1," + num2Lon + "/1," + num3Lon + "/1000");

if (latitude > 0) {
exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE_REF, "N");
} else {
exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE_REF, "S");
}

if (longitude > 0) {
exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF, "E");
} else {
exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF, "W");
}
exif.setAttribute(ExifInterface.TAG_MAKE, "FooBarr");
exif.setAttribute(ExifInterface.TAG_MODEL, "KooKKoo");
exif.setAttribute(ExifInterface.TAG_ORIENTATION,orientation+"");
exif.saveAttributes();

关于android - 将元数据添加到 Android 中创建的位图中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23756716/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com