我有一些代码,用户在屏幕上绘制内容,我想将其作为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所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)