1

我的应用程序使用相机拍照并将数据发送到其他地方。但是,就字节而言,图片尺寸太大,或者不必要地大。但我不知道如何强制相机拍一张更小的照片,或者在拍完照片后,发送一个缩小版的照片。

这就是我进入相机屏幕的方式。

Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
intent.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(getTempFile()));

startActivityForResult(intent, PIC_ONE);//first picture

然后 onActivityResult 我有:

...
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize=4;
Bitmap mBitmap = BitmapFactory.decodeFile(getPath(myURI),options);

photoView.setImageBitmap(bmp);

它向用户显示了已保存图像的四分之一大小的缩略图。但当然实际图像仍然保留其大尺寸。

如何减小图像尺寸?

4

1 回答 1

1

看看使用 BitmapFactory.Options.inSampleSize 减少位图大小


您也可以尝试createScaledBitmap()

public static Bitmap createScaledBitmap (Bitmap src, int dstWidth, int dstHeight, boolean filter) 

自:API 级别 1 创建一个新位图,从现有位图缩放。

参数 src 源位图。dstWidth 新位图的所需宽度。dstHeight 新位图的所需高度。如果应该过滤源,则过滤器为真。

返回新的缩放位图

它还减少了文件大小,

您还可以使用以下功能来调整大小:

 public Bitmap getResizedBitmap(Bitmap bm, int newHeight, int newWidth) {

    int width = bm.getWidth();

    int height = bm.getHeight();

    float scaleWidth = ((float) newWidth) / width;

    float scaleHeight = ((float) newHeight) / height;

    // create a matrix for the manipulation

    Matrix matrix = new Matrix();

    // resize the bit map

    matrix.postScale(scaleWidth, scaleHeight);

    // recreate the new Bitmap

    Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false);

    return resizedBitmap;

    }
于 2012-06-03T16:55:05.930 回答