我用手机摄像头拍了一张照片并将它存储在变量“photo”中
Bitmap photo = (Bitmap) data.getExtras().get("data");
我也用手机gps获取了经纬度
lat = location.getLatitude();
lon = location.getLongitude();
如何仅将此 gps 数据合并到图像中?
附言用户可以通过在相机设置中启用 GPS 标签选项来手动捕获带有 GPS 标签的图像。我想确保拍摄的图像强制带有 GPS 标记。
最佳答案
你不能将它设置为位图,位图只是一个带有图像像素的字节数组。 将其保存到支持元数据(例如 PNG 或 JPG)的文件后,您必须应用这些坐标
为此,您可以使用 ExifInterface
代码类似:
String filePath = Enviroment.getExternalStorageDirectory() + "/MyApp/photo.png";
OutputStream out = new BufferedOutputStream(new FileOutputStream(new File(filePath)));
photo.compress(Bitmap.CompressFormat.PNG, 100, out);
out.flush();
out.close();
ExifInterface exif = new ExifInterface(filePath);
// call this next setAttributes a few times to write all the GPS data to it.
exif.setAttribute(... );
// don't forget to save
exif.saveAttributes();
关于android - GPS 标记在 android 中捕获的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19023830/