开发者

How do I convert byte[] to Bitmap?

开发者 https://www.devze.com 2023-03-27 03:56 出处:网络
Let\'s say I have a byte buffe开发者_StackOverflow社区r and how do I get Bitmap?If you want to manipulate the image, use ImageIO. It creates a format-agnostic image in memory:

Let's say I have a byte buffe开发者_StackOverflow社区r and how do I get Bitmap?


If you want to manipulate the image, use ImageIO. It creates a format-agnostic image in memory:

BufferedImage img = ImageIO.read(new ByteArrayInputStream(bytes));

If you just want to store in to disk, then simply write the byte array to a file.

Note that the byte array must be already a bitmap image, you can't take any byte array and have it as bitmap.

And you get the byte array from the byte buffer by:

byte[] bytes = new byte[buf.capacity()];
buf.get(bytes, 0, bytes.length);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号