我使用以下代码调整位图的大小:
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 文件管理器中),也是我在 Canvas 上的应用程序中绘制位图时看到的。这种情况发生在我测试过的每台设备上(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);
最佳答案
1) 尝试在调用 createScaledBitmap() 时将过滤器参数从“false”更改为“true”。我打赌这会解决您的问题。
您应该阅读这篇文章:http://www.curious-creature.org/2010/12/08/bitmap-quality-banding-and-dithering/
关于android - 在 Android 中调整位图大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5995022/