简体   繁体   English

为什么我的应用拍摄的照片在Android中为0尺寸?

[英]Why pictures taken by my app are 0 size in Android?

Pictures taken by my app, in Windows Explorer have always 0 bytes and can't be opened. 我的应用在Windows资源管理器中拍摄的照片始终为0字节,无法打开。 I can only see them in Android Gallery app. 我只能在Android Gallery应用中看到它们。

I am taking photo with this method : 我正在用这种方法拍照:

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);
        }
    }
}

And this is PhotoUtils.createImageFile(...) : 这是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);
    }

You are indexing the file when it is zero bytes long, in the form of your temp file. 您正在以临时文件的形式为长度为零字节的文件建立索引。 Try moving your galleryAddPic() call until after the picture has been taken. 尝试移动您的galleryAddPic()调用,直到拍摄完照片为止。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 增加使用Android相机拍摄的照片的大小 - increase the size of the pictures taken with android camera 在哪里存储从Android应用程序拍摄的照片 - Where to store pictures taken from Android app 在Android应用程序中保存相机拍摄的照片 - saving pictures taken by camera in android app 我可以通过我的应用程序监视Android原生相机应用程序拍摄的照片吗? - Can I monitor pictures taken by Android native camera app via my app? 如何使我的App拍摄的照片可备份 - How to make pictures taken by my App backup-able 为什么在图库中看不到我拍摄的照片? - Why can't I see my taken pictures in gallery? 在我的Android应用中访问图片应用中的图片 - Access pictures from Pictures app in my android app 使用相机拍摄的照片的图像格式(Android手机) - Image format of pictures taken with the camera (Android phones) 如果图片是使用 android 的相机应用程序拍摄的,为什么我无法在我的 android 应用程序中上传图片库中的图片? - Why can't I upload a picture from gallery in my android app, if the picture was taken with the camera app from android? Android:为什么将Android应用程序的名称作为起始活动的名称? - Android: Why is the name of the android app taken as the name of the starting activity?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM