我使用以下代码调整位图的大小:
FileOutputStream out = new FileOutputStream("/sdcard/mods.png");
Bitmap bmp = Bitmap.createScaledBitmap(pict, (int)(pict.getWidth() / totScale),
(int)(pict.getHeight() / totScale), false);
bmp.compress(Bitmap.CompressFormat.PNG, 90, out);
out.close();
从我正在使用的相机获取位图的代码如下:
mCamera.takePicture(null, null, null, new Camera.PictureCallback() {
@Override
public void onPictureTaken(byte[] data, Camera camera) {
pict = BitmapFactory.decodeByteArray(data, 0, data.length);
}
});
第一张图片是我在手机上(在 Astro 文件管理器中)以及当我在画布上在应用程序中绘制位图时看到的图片。这种情况发生在我测试过的每台设备上(HTC Legend 和 Galaxy Tab)。第二张图片是它在我的计算机上的样子。是什么导致设备上出现阻塞?
解决方案:
这是解决我的问题的方法:
代替
pict = BitmapFactory.decodeByteArray(data, 0, data.length);
我把它替换为
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inPreferredConfig = Bitmap.Config.ARGB_8888;
pict = BitmapFactory.decodeByteArray(data, 0, data.length, opts);