在Android中调整位图大小 [英] Resize Bitmap in Android

查看:138
本文介绍了在Android中调整位图大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码调整位图:

  FileOutputStream out = new FileOutputStream(/ sdcard / mods.png ); 
Bitmap bmp = Bitmap.createScaledBitmap(pict,(int)(pict.getWidth()/ totScale),
(int)(pict.getHeight()/ totScale)
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);





解决方案

1)在调用createScaledBitmap时,尝试将filter参数从false更改为true ()。我敢打赌,这将解决你的问题。



你应该阅读这篇文章: http://www.curious-creature.org/2010/12/08/bitmap-quality-banding-and-dithering/


I resize a bitmap using the following code:

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();

The code for getting the bitmap from the camera that I am using is the following:

mCamera.takePicture(null, null, null, new Camera.PictureCallback() {
        @Override
        public void onPictureTaken(byte[] data, Camera camera) {
            pict = BitmapFactory.decodeByteArray(data, 0, data.length);
        }
});

The first picture is what I can see on the phone (in Astro file manager), and also when I draw the bitmap in my application on a canvas. This happens on every device I've tested on (HTC Legend and Galaxy Tab) The second picture is what it looks like on my computer. What is causing the blocks on the device?


Solution:

Here is what fixed my problem: Instead of

pict = BitmapFactory.decodeByteArray(data, 0, data.length);

I replaced that with

BitmapFactory.Options opts = new BitmapFactory.Options();               
opts.inPreferredConfig = Bitmap.Config.ARGB_8888;
pict = BitmapFactory.decodeByteArray(data, 0, data.length, opts);


解决方案

1) Try changing the filter parameter from "false" to "true" in your call to createScaledBitmap(). I bet that will fix your problem.

You should read this article: http://www.curious-creature.org/2010/12/08/bitmap-quality-banding-and-dithering/

这篇关于在Android中调整位图大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆