图像文件缺少 exif 数据
Image file missing exif data
使用 intent 拍摄照片,稍后上传到服务器。
图像首先像这样保存到 sdcard:
/**
* Creating file uri to store image/video
*/
public Uri getOutputMediaFileUri(int type) {
return Uri.fromFile(getOutputMediaFile(type));
}
/**
* returning image / video
*/
private static File getOutputMediaFile(int type) {
// External sdcard location
File mediaStorageDir = new File(
Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
Config.IMAGE_DIRECTORY_NAME);
// Create the storage directory if it does not exist
if (!mediaStorageDir.exists()) {
if (!mediaStorageDir.mkdirs()) {
Log.d(TAG, "Oops! Failed create "
+ Config.IMAGE_DIRECTORY_NAME + " directory");
return null;
}
}
// Create a media file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss",
Locale.getDefault()).format(new Date());
File mediaFile;
if (type == MEDIA_TYPE_IMAGE) {
mediaFile = new File(mediaStorageDir.getPath() + File.separator
+ "IMG_" + timeStamp + ".jpg");
} else if (type == MEDIA_TYPE_VIDEO) {
mediaFile = new File(mediaStorageDir.getPath() + File.separator
+ "VID_" + timeStamp + ".mp4");
} else {
return null;
}
return mediaFile;
}
保存的图片没有exif数据。是因为uri吗? (使用默认相机应用拍摄的照片有 exif 数据,所以它一定是我的应用中的一个问题)。
编辑:用于启动默认相机应用程序的代码:
/**
* Launching camera app to capture image
*/
private void captureImage() {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
// start the image capture Intent
startActivityForResult(intent, CAMERA_CAPTURE_IMAGE_REQUEST_CODE);
}
url 存储:
/**
* Here we store the file url as it will be null after returning from camera
* app
*/
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
// save file url in bundle as it will be null on screen orientation
// changes
outState.putParcelable("file_uri", fileUri);
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
// get the file url
fileUri = savedInstanceState.getParcelable("file_uri");
}
photos taken with the default camera app has exif data so it has to be an issue in my app
不一定。从您显示的代码来看,它似乎是该特定相机应用程序中的错误。并非所有相机应用开发者都ACTION_IMAGE_CAPTURE
测试得很好。除非您在拍摄照片后但在 运行 EXIF 测试之前的某个时间修改图像,否则相机应用程序不会向通过 ACTION_IMAGE_CAPTURE
拍摄的照片添加 EXIF 标签。 These things happen.
您可以安装一些相机应用程序并查看它们在 ACTION_IMAGE_CAPTURE
中的表现。例如,Open Camera 支持 ACTION_IMAGE_CAPTURE
,但我还没有测试它在 ACTION_IMAGE_CAPTURE
时的 EXIF 行为。
使用 intent 拍摄照片,稍后上传到服务器。 图像首先像这样保存到 sdcard:
/**
* Creating file uri to store image/video
*/
public Uri getOutputMediaFileUri(int type) {
return Uri.fromFile(getOutputMediaFile(type));
}
/**
* returning image / video
*/
private static File getOutputMediaFile(int type) {
// External sdcard location
File mediaStorageDir = new File(
Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
Config.IMAGE_DIRECTORY_NAME);
// Create the storage directory if it does not exist
if (!mediaStorageDir.exists()) {
if (!mediaStorageDir.mkdirs()) {
Log.d(TAG, "Oops! Failed create "
+ Config.IMAGE_DIRECTORY_NAME + " directory");
return null;
}
}
// Create a media file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss",
Locale.getDefault()).format(new Date());
File mediaFile;
if (type == MEDIA_TYPE_IMAGE) {
mediaFile = new File(mediaStorageDir.getPath() + File.separator
+ "IMG_" + timeStamp + ".jpg");
} else if (type == MEDIA_TYPE_VIDEO) {
mediaFile = new File(mediaStorageDir.getPath() + File.separator
+ "VID_" + timeStamp + ".mp4");
} else {
return null;
}
return mediaFile;
}
保存的图片没有exif数据。是因为uri吗? (使用默认相机应用拍摄的照片有 exif 数据,所以它一定是我的应用中的一个问题)。
编辑:用于启动默认相机应用程序的代码:
/**
* Launching camera app to capture image
*/
private void captureImage() {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
// start the image capture Intent
startActivityForResult(intent, CAMERA_CAPTURE_IMAGE_REQUEST_CODE);
}
url 存储:
/**
* Here we store the file url as it will be null after returning from camera
* app
*/
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
// save file url in bundle as it will be null on screen orientation
// changes
outState.putParcelable("file_uri", fileUri);
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
// get the file url
fileUri = savedInstanceState.getParcelable("file_uri");
}
photos taken with the default camera app has exif data so it has to be an issue in my app
不一定。从您显示的代码来看,它似乎是该特定相机应用程序中的错误。并非所有相机应用开发者都ACTION_IMAGE_CAPTURE
测试得很好。除非您在拍摄照片后但在 运行 EXIF 测试之前的某个时间修改图像,否则相机应用程序不会向通过 ACTION_IMAGE_CAPTURE
拍摄的照片添加 EXIF 标签。 These things happen.
您可以安装一些相机应用程序并查看它们在 ACTION_IMAGE_CAPTURE
中的表现。例如,Open Camera 支持 ACTION_IMAGE_CAPTURE
,但我还没有测试它在 ACTION_IMAGE_CAPTURE
时的 EXIF 行为。