【问题标题】:Android: how to define image parameters (size? format? filesize) when using MediaStore.ACTION_IMAGE_CAPTUREAndroid:使用 MediaStore.ACTION_IMAGE_CAPTURE 时如何定义图像参数(大小?格式?文件大小)
【发布时间】:2011-12-21 07:58:57
【问题描述】:

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

我正在使用意图 MediaStore.ACTION_IMAGE_CAPTURE。 我可以以某种方式操纵这些参数吗?

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

然后我想我可以在保存之前对拍摄的图像进行操作。

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

【问题讨论】:

    标签: android camera size format


    【解决方案1】:

    根据我的经验,您无法通过为此意图提供参数来设置图像的大小。 如果你会添加这样的东西
    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);
    

    【讨论】:

    • 为什么在最低分辨率下进行缩放? (默认情况下)320x640 更接近。
    猜你喜欢
    • 1970-01-01
    • 2012-06-19
    • 1970-01-01
    • 2014-10-29
    • 2023-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多