【发布时间】:2011-08-25 02:23:40
【问题描述】:
我使用以下代码调整位图的大小:
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);
【问题讨论】:
-
你们中最喜欢花时间发布确切解决方案的人(upvote)。