如何获得全分辨率图片

时间:2016-05-25 16:21:03

标签: android

您好我创建了一个Android代码拍照,代码运行良好但是当我得到一个图片副本时,分辨率非常低。我怎样才能获得完整的分辨率。 这是我的代码:

private void cameraIntent()
{
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    intent.putExtra( MediaStore.EXTRA_OUTPUT, this.destinationUpload);
    startActivityForResult(intent, REQUEST_CAMERA);
}

private void onCaptureImageResult(Intent data) {
    Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    thumbnail.compress(Bitmap.CompressFormat.JPEG, 100, bytes);

    File destination = new File(Environment.getExternalStorageDirectory(),"img.jpg");

    FileOutputStream fo;
    try {
        destination.createNewFile();
        fo = new FileOutputStream(destination);
        fo.write(bytes.toByteArray());
        fo.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

}

1 个答案:

答案 0 :(得分:2)

您将获得支持所有不同相机应用程序的乐趣。

你在那里的一半。文档说

  

调用者可以传递额外的EXTRA_OUTPUT来控制该图像的写入位置。如果是EXTRA_OUTPUT

intent.putExtra( MediaStore.EXTRA_OUTPUT, this.destinationUpload);

告诉相机应用将图像保存到destinationUpload的文件中。现在您可以读取该文件,或者您可以获得该文件的MediaStore URI。后者将更好地分享。

使用

MediaScannerConnection.scanFile(context, new String[]{file.getAbsolutePath()}, null, new MediaScannerConnection.OnScanCompletedListener() {
        @Override
        public void onScanCompleted(String path, Uri uri) {
            callback.result(uri);
        }
    });