Bitmap.com preSS返回false用于绘制图像 [英] Bitmap.compress returns false for drawn image

查看:249
本文介绍了Bitmap.com preSS返回false用于绘制图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些code,用户绘制屏幕上的内容,我想将其存储在一个byte []一个PNG。然而,COM preSS()方法返回false。任何想法,这是为什么?有没有更好的方式来获得的byte []?

I have some code where the user draws something on the screen and I want to store it as a PNG in a byte[]. However, the compress() method returns false. Any idea why that is? Is there a better way to get the byte[]?

Bitmap bm = Bitmap.createBitmap(mWidth, mHeight, Bitmap.Config.ALPHA_8);
Canvas c = new Canvas(bm);
c.drawPath(mSignaturePath, mSignaturePaint);
ByteArrayOutputStream out = new ByteArrayOutputStream();
if (bm.compress(Bitmap.CompressFormat.PNG, 100, out)) {
    byte[] result = out.toByteArray(); // Never gets called
}

在此先感谢。

Thanks in advance.

推荐答案

问题是如何,我创建映像:

The problem was in how I was creating the image:

Bitmap bm = Bitmap.createBitmap(mWidth, mHeight, Bitmap.Config.ALPHA_8);

当我改变了这一切,以 Bitmap.Config.RGB_565 它工作得很好。

When I changed that to Bitmap.Config.RGB_565 it worked fine.

感谢马克·墨菲(@commonsware)的意见,在他的办公室小时!

Thanks to Mark Murphy (@commonsware) for the advice during his office hours!

这篇关于Bitmap.com preSS返回false用于绘制图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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