开发者

How would I convert a PNG Image into a byte array?

开发者 https://www.devze.com 2023-03-25 08:23 出处:网络
Using G开发者_StackOverflow中文版WT I would like to read a PNG image and have the data accessible to me as a decoded byte array.

Using G开发者_StackOverflow中文版WT I would like to read a PNG image and have the data accessible to me as a decoded byte array.

On the client side I get the image using an ImageBundle, I then instantiate an Image and call setUrl.

At this point, how do I get the image byte array from the image?


You can't. Javascript (and hence GWT) do not have access to images' data when images are presented as html images (i.e. as <img> tag or css background image).

What you could do is load image data via RPC, process it, Base64 encode it and then create image via embedded url: "data:image/png;base64,..yourBase64Datahere.."

If you are trying to do some visual manipulation you should consider:

  1. Manipulating image on the server.

  2. Using html canvas or svg.

0

精彩评论

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

关注公众号