簡體   English   中英

為什么我的應用拍攝的照片在Android中為0尺寸?

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

我的應用在Windows資源管理器中拍攝的照片始終為0字節,無法打開。 我只能在Android Gallery應用中看到它們。

我正在用這種方法拍照:

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

您正在以臨時文件的形式為長度為零字節的文件建立索引。 嘗試移動您的galleryAddPic()調用,直到拍攝完照片為止。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM