从相机意图的完整图像

时间:2014-10-21 13:18:40

标签: android

我正在使用相机并希望从位图获取完整图像。目前我有一个缩略图的位图大小,所以当我尝试缩放它时,图像看起来模糊和拉伸。我也在sdcard上的app文件夹中保存图像。如何从位图获取完整大小的图像? 感谢

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


 if (requestCode == CAMERA_PIC_REQUEST) {

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

//我尝试过缩放和使用矩阵,但不能提高图像的质量

    Bitmap scaledBitmap = Bitmap.createBitmap(612, 936, Config.ARGB_8888);

              float scaleX = 612 / (float) bitmap.getWidth();
              float scaleY = 936 / (float) bitmap.getHeight();
              float pivotX = 0;
              float pivotY = 0;

              Matrix scaleMatrix = new Matrix();
              scaleMatrix.setScale(scaleX, scaleY, pivotX, pivotY);

              Canvas canvas = new Canvas(scaledBitmap);
              canvas.setMatrix(scaleMatrix);

              Paint paint = new Paint();
              paint.setAntiAlias(true);
              paint.setFilterBitmap(true);
              paint.setDither(true);

              canvas.drawBitmap(bitmap, 0, 0, paint);

1 个答案:

答案 0 :(得分:1)

Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
String picturePath = "/path";
File imageFile = new File(picturePath);
Uri imageFileUri = Uri.fromFile(imageFile);
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, imageFileUri);
startActivityForResult(intent, CAMERA_PIC_REQUEST);