在Android中捕获具有原始分辨率的app内的照片

时间:2014-08-14 14:44:34

标签: android android-intent android-camera

我使用相机意图捕获我的Android应用内的图像。捕获后,我将图片保存到特定文件夹中的移动内部/外部存储。问题是这些照片没有保存在相机正常的分辨率下,它们的分辨率非常低。

这是我的代码

Intent intent = new Intent(
                android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
        startActivityForResult(intent, 0); 

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // TODO Auto-generated method stub
        super.onActivityResult(requestCode, resultCode, data);
        Bitmap bp = (Bitmap) data.getExtras().get("data");

        /*********** Load Captured Image And Data Start ****************/
        String extr = Environment.getExternalStorageDirectory().toString()
                + File.separator + "ScannerMini";
        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss")
                .format(new Date());
         imageName = timeStamp + ".jpg";

        if (Environment.MEDIA_MOUNTED.equals(state)) {
            // We can read and write the media
            myPath = new File(getExternalFilesDir(filepath), imageName);
            //File myPath = new File(extr, imageName);
        }
        else{
         myPath = new File(extr, imageName);
        }
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream(myPath);
            bp.compress(Bitmap.CompressFormat.JPEG, 100, fos);
            fos.flush();
            fos.close();

            MediaStore.Images.Media.insertImage(getApplicationContext()
                    .getContentResolver(), bp, myPath.getPath(), imageName);

        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }


    }

任何人都可以告诉我,我该怎么做才能以原始分辨率保存图像。任何帮助将非常感激。谢谢你:)

1 个答案:

答案 0 :(得分:2)

Bitmap bp = (Bitmap) data.getExtras().get("data");

通过这样做,您将只获得缩略图。您需要在捕获意图中指定MediaStore.EXTRA_OUTPUT选项。这是存储捕获图像的路径。请参阅android docs Taking Photos Simply