package com.akjava.gwt.lib.client;

import com.google.gwt.canvas.client.Canvas;
import com.google.gwt.dom.client.ImageElement;
import com.google.gwt.user.client.ui.Image;

public class CanvasUtils {
public static Canvas createCanvas(int w,int h){
	Canvas canvas=Canvas.createIfSupported();
	if(canvas!=null){
		canvas.setCoordinateSpaceWidth(w);
		canvas.setCoordinateSpaceHeight(h);
		canvas.setWidth(w+"px");
		canvas.setHeight(h+"px");
	}
	return canvas;
}
/*
 * if you need use ImageElementLoader
 */
public static ImageElement toImageElement(Canvas canvas){
	Image img=new Image(canvas.toDataUrl());
	ImageElement imageElement=ImageElement.as(img.getElement());
	return imageElement;
}

public static String createColorImageDataUrl(int r,int g,int b,double opacity,int w,int h){
	Canvas canvas=CanvasUtils.createCanvas(w, h);
	canvas.getContext2d().setFillStyle("rgba("+r+","+g+","+b+","+opacity+")");
	canvas.getContext2d().fillRect(0, 0, w, h);
	String image1=canvas.toDataUrl();
	return image1;
}
}

@@ -1031,11 +1031,770 @@
 e1;%0D%0A%7D%0D%0A
+%0D%0Apublic static String createCircleImageDataUrl(int r,int g,int b,double opacity,double radius,double lineWidth,boolean stroke)%7B%0D%0A%09double center=radius+lineWidth;%0D%0A%09Canvas canvas=CanvasUtils.createCanvas((int)center*2,(int)center*2);%0D%0A%09if(stroke)%7B%0D%0A%09canvas.getContext2d().setStrokeStyle(%22rgba(%22+r+%22,%22+g+%22,%22+b+%22,%22+opacity+%22)%22);%0D%0A%09canvas.getContext2d().setLineWidth(lineWidth);%0D%0A%09%7Delse%7B%0D%0A%09canvas.getContext2d().setFillStyle(%22rgba(%22+r+%22,%22+g+%22,%22+b+%22,%22+opacity+%22)%22);%09%0D%0A%09%7D%0D%0A%09canvas.getContext2d().beginPath();%0D%0A%09%0D%0A%09canvas.getContext2d().arc(center, center, radius, 0, 360);%0D%0A%09canvas.getContext2d().closePath();%0D%0A%09if(stroke)%7B%0D%0A%09%09canvas.getContext2d().stroke();%0D%0A%09%7Delse%7B%0D%0A%09%09canvas.getContext2d().fill();%0D%0A%09%7D%0D%0A%09String image1=canvas.toDataUrl();%0D%0A%09return image1;%0D%0A%7D%0D%0A%0D%0A
 %7D%0D%0A

add canvas draw circle