android–Bitmap.compress为绘制的图像返回false

android–Bitmap.compress为绘制的图像返回false,第1张

概述我有一些代码,用户在屏幕上绘制内容,我想将其作为PNG存储在byte[]中.但是,compress()方法返回false.知道为什么会这样吗?是否有更好的方法来获取byte[]?Bitmapbm=Bitmap.createBitmap(mWidth,mHeight,Bitmap.Config.ALPHA_8);Canvasc=newCanvas(bm);c.drawPath(mSigna

我有一些代码,用户在屏幕上绘制内容,我想将其作为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全部内容,希望文章能够帮你解决android – Bitmap.compress为绘制的图像返回false所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1096593.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存