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

Sha*_*zon 7 png android canvas bitmap

我有一些代码,用户在屏幕上绘制内容,我想将其作为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
}
Run Code Online (Sandbox Code Playgroud)

提前致谢.

Sha*_*zon 8

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

Bitmap bm = Bitmap.createBitmap(mWidth, mHeight, Bitmap.Config.ALPHA_8);
Run Code Online (Sandbox Code Playgroud)

当我改变它,Bitmap.Config.RGB_565它工作得很好.

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