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

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

问题描述

我用下面的code调整位图:

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

在$ C $下获得的,我用相机的位图如下:

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

第一张照片是我可以在手机上看到(在天文文件管理器),并且还当我绘制位图在我的画布上的应用程序。这发生在每一个设备,我对(HTC传奇和银河标签)测试的第二张照片是什么样子的我的电脑上。是什么原因造成这些块设备上?

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?


下面是固定我的问题: 而不是

Here is what fixed my problem: Instead of

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假到真()改变滤波器参数。我敢打赌,这将解决您的问题。

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

您应该看看这篇文章:的http://www.curious-creature.org/2010/12/08/bitmap-quality-banding-and-dithering/

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

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

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