繁体   English   中英

Bitmap.compress对绘制的图像返回false

[英]Bitmap.compress returns false for drawn image

我有一些代码,用户在屏幕上绘制内容,我想将其作为PNG存储在byte []中。 但是,compress()方法返回false。 知道为什么会这样吗? 是否有更好的方法来获取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
}

提前致谢。

问题在于我是如何创建图像的:

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

当我将其更改为Bitmap.Config.RGB_565它运行正常。

感谢Mark Murphy(@commonsware)在办公时间提供建议!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM