从相机保存图像而不调整大小

Save image from camera without being resized

我使用以下代码创建图像文件并将它们保存到 sd 卡

 private File createImageFile(Bitmap bitmap) throws IOException {
        File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
        File image = File.createTempFile(
                PICNAME,
                ".png",
                storageDir);
        FileOutputStream out = null;
        try {
            out = new FileOutputStream(image);
            bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return image;
    }

问题是,虽然我在全屏模式下拍照,但上面的代码总是以非常小的尺寸(320x240)保存图像。为什么这样.. 有什么方法可以在不调整大小的情况下保存图像吗?

你可以这样做:

public static Uri takePhotoByCamera(Activity activity) {
    File publicDirectory = Environment
            .getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES + "/myFolder");
    double d = new Random().nextDouble();
    File file = new File(publicDirectory, d + ".jpg");
    String path = file.getAbsolutePath();
    ContentValues values = new ContentValues();
    values.put(MediaStore.MediaColumns.DATA, path);
    values.put(MediaStore.MediaColumns.TITLE, "New Picture");
    values.put(MediaStore.Images.ImageColumns.DESCRIPTION, "From your Camera");
    activity.getContentResolver().insert(
            MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
    Uri photoUri = Uri.parse("file://" + path);
    if (!publicDirectory.exists())
        publicDirectory.mkdirs();
    else if (!publicDirectory.isDirectory() && publicDirectory.canWrite()) {
        publicDirectory.delete();
        publicDirectory.mkdirs();
    } else {
        Log.d("tag550", "can't access");
    }
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);
    activity.startActivityForResult(intent, requestCamera);
    return photoUri;
}