开发者

How can i create .png transparent image in GWT? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
开发者_JAVA技巧

Want to improve this question? Update the question so it focuses on one problem only by editing this post.

Closed 2 years ago.

Improve this question

i want to Generate .png image in GWT

Does anyone know about this?


With GWT 2.4, and HTML canvas, you can do it on the browser side. Create a canvas element, draw whatever you want on it and then get a data url which contains the image as png data. This will only work on browsers that support it (most modern browsers do, IE <= 8 won't support it as far as I know but you can use explorercanvas).

Example code (untested):

Canvas canvas = Canvas.createIfSupported();

canvas.setCoordinateSpaceWidth(100);
canvas.setCoordinateSpaceHeight(100);

canvas.getContext2D().setStrokeStyle("black");
canvas.getContext2D().lineTo(100, 100);
canvas.getContext2D().stroke();

String pngDataUrl = canvas.toDataUrl("image/png");
Image image = new Image(pngDataUrl);

At the end of this code, pngDataUrl will have the png image encoded as a data url. image will display the canvas' contents as a regular PNG image in the browser.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜