在android中从byteArray创建Bitmap
我想从 bytearray 创建位图。
我尝试了以下代码
Bitmap bmp;
bmp = BitmapFactory.decodeByteArray(data, 0, data.length);
,
ByteArrayInputStream bytes = new ByteArrayInputStream(data);
BitmapDrawable bmd = new BitmapDrawable(bytes);
bmp = bmd.getBitmap();
但是,当我尝试使用位图初始化 Canvas 对象时,
Canvas canvas = new Canvas(bmp);
会导致错误
java.lang.IllegalStateException: Immutable bitmap passed to Canvas constructor
然后如何从 byteArray 获取可变位图。
提前致谢。
I want to create a bitmap from a bytearray .
I tried the following codes
Bitmap bmp;
bmp = BitmapFactory.decodeByteArray(data, 0, data.length);
and
ByteArrayInputStream bytes = new ByteArrayInputStream(data);
BitmapDrawable bmd = new BitmapDrawable(bytes);
bmp = bmd.getBitmap();
But ,When i am tring to initialize the Canvas object with the bitmap like
Canvas canvas = new Canvas(bmp);
It leads to an error
java.lang.IllegalStateException: Immutable bitmap passed to Canvas constructor
Then how to get a mutable bitmap from an byteArray.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要一个可变的位图才能创建画布。
编辑:正如诺亚·塞德曼所说,您可以在不创建副本的情况下完成此操作。
You need a mutable
Bitmap
in order to create theCanvas
.Edit: As Noah Seidman said, you can do it without creating a copy.