Android:如何定义图像参数(大小?格式吗?当使用MediaStore.ACTION_IMAGE_CAPTURE时



我有一个具有拍照功能的应用程序。我拍摄的图像有一个定义的大小,高度x宽度。

我使用的意图MediaStore.ACTION_IMAGE_CAPTURE。我能改变这些参数吗?

我发现了其他的解决方案-创建我自己的相机活动使用SurfaceView指定的链接:[http://itp.nyu.edu/~ sve204/mobilemedia_spring10/androidCamera101.pdf] [1]

那么我想我可以在保存之前对图像进行操作。

这是一个好方法吗?我可以继续使用mediaststore吗?ACTION_IMAGE_CAPTURE意图?通常是怎么做的?

根据我的经验,你不能通过向这个意图提供参数来设置图像的大小。如果你添加这样的东西
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT,location_of_image_to_save);,它将返回相机设置的默认大小的图片。稍后,您可以使用以下代码更改图像的大小

            int width = photo.getWidth();
            int height = photo.getHeight();
            int newWidth =3000;
            int newHeight =3000; 
            float scaleWidth = ((float) newWidth) / width;// calculate the scale - in this case = 0.4f
            float scaleHeight = ((float) newHeight) / height;
            // createa matrix for the manipulation
            Matrix matrix = new Matrix();
            // resize the bit map
            matrix.postScale(scaleWidth, scaleHeight);
            // rotate the Bitmap

            // recreate the new Bitmap
            Bitmap.createBitmap(photo, 0, 0,width, height, matrix, true);
            Bitmap resizedBitmap = Bitmap.createBitmap(photo, 0, 0, 1000, 1000);

最新更新