如何使用GWT将PNG图像数据作为解码字节数组获取? [英] How do I get PNG image data as a decoded byte array using GWT?

查看:112
本文介绍了如何使用GWT将PNG图像数据作为解码字节数组获取?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用GWT我想读取一个PNG图像,并将数据作为解码的字节数组访问。

Using GWT I would like to read a PNG image and have the data accessible to me as a decoded byte array.

在客户端,我使用ImageBundle获取图像,然后实例化Image并调用setUrl。

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?

推荐答案

我不确定是否存在没有跨浏览器的方式来获取图像的字节数组,因为我们毕竟在JavaScript里。您可以创建一个新的画布元素,将图像添加到canvas.context2D并阅读canvas.context2D.data属性,以获得每个像素具有RGBA值的数组。

I'm not sure if there is no cross browser way to get the byte array of an image cause we are in JavaScript land after all. You can create a new canvas element, add the image to the canvas.context2D and read the canvas.context2D.data atribute to get an array with RGBA values of every pixel.

看起来gwt支持最新版本的canvas元素,因此您可以将它归档为纯Java:
http://google-web-toolkit.googlecode.com/svn/javadoc/latest/com/google/gwt/canvas/dom /client/ImageData.html

Seems gwt supports the canvas element in the latest version so you can archive this in pure Java: http://google-web-toolkit.googlecode.com/svn/javadoc/latest/com/google/gwt/canvas/dom/client/ImageData.html

这篇关于如何使用GWT将PNG图像数据作为解码字节数组获取?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆