0
Windows 탐색기에서 내 앱으로 찍은 사진은 항상 0 바이트이며 열 수 없습니다. Android Gallery 앱에서만 볼 수 있습니다.왜 내 사진이 찍은 사진이 Android에서 크기가 0입니까?
나는이 방법으로 사진을 복용하고 있습니다 :
private void takePhoto() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
File photoFile = null;
try {
photoFile = PhotoUtils.createImageFile(this);
} catch (IOException ex) {
Log.v("MainActivity", "Creating image exception");
}
if (photoFile != null) {
fileUri = Uri.fromFile(photoFile);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
}
}
}
그리고 이것은 PhotoUtils.createImageFile(...)
입니다 :
public static File createImageFile(Context context) throws IOException {
String currentPhotoPath;
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "ES_" + timeStamp;
File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
File image = File.createTempFile(imageFileName, ".jpg", storageDir);
currentPhotoPath = image.getAbsolutePath();
galleryAddPic(context, currentPhotoPath);
return image;
}
public static void galleryAddPic(Context context, String currentPhotoPath) {
Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
File f = new File(currentPhotoPath);
Uri contentUri = Uri.fromFile(f);
mediaScanIntent.setData(contentUri);
context.sendBroadcast(mediaScanIntent);
}