我有一些代码,用户可以在屏幕上绘制一些东西,我想将它作为 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) 在办公时间提供的建议!
关于android - Bitmap.compress 为绘制的图像返回 false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6063764/