本文整理汇总了Java中com.google.gwt.canvas.dom.client.ImageData类的典型用法代码示例。如果您正苦于以下问题:Java ImageData类的具体用法?Java ImageData怎么用?Java ImageData使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ImageData类属于com.google.gwt.canvas.dom.client包,在下文中一共展示了ImageData类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createCanvas
import com.google.gwt.canvas.dom.client.ImageData; //导入依赖的package包/类
public static Canvas createCanvas(int [] pixels, int width, int height) {
Canvas canvas = Canvas.createIfSupported();
if(canvas == null) return null;
canvas.setCoordinateSpaceWidth(width);
canvas.setCoordinateSpaceHeight(height);
Context2d context = canvas.getContext2d();
ImageData data = context.createImageData(width, height);
CanvasPixelArray array = data.getData();
for(int i=0; i<width*height; i++) { // ABGR
array.set(4*i+0, pixels[i] & 0xFF);
array.set(4*i+1, (pixels[i] >> 8) & 0xFF);
array.set(4*i+2, (pixels[i] >> 16) & 0xFF);
array.set(4*i+3, (pixels[i] >> 24) & 0xFF);
}
context.putImageData(data, 0, 0);
return canvas;
}
示例2: createImageCanvas
import com.google.gwt.canvas.dom.client.ImageData; //导入依赖的package包/类
Canvas createImageCanvas(int [] pixels, int width, int height) {
Canvas canvas = Canvas.createIfSupported();
canvas.setCoordinateSpaceWidth(width);
canvas.setCoordinateSpaceHeight(height);
Context2d context = canvas.getContext2d();
ImageData data = context.createImageData(width, height);
CanvasPixelArray array = data.getData();
for(int i=0; i<width*height; i++) {
array.set(4*i+0, pixels[i] & 0xFF);
array.set(4*i+1, (pixels[i] >> 8) & 0xFF);
array.set(4*i+2, (pixels[i] >> 16) & 0xFF);
array.set(4*i+3, (pixels[i] >> 24) & 0xFF);
}
context.putImageData(data, 0, 0);
return canvas;
}
示例3: createImageCanvas
import com.google.gwt.canvas.dom.client.ImageData; //导入依赖的package包/类
private Canvas createImageCanvas(int [] pixels, int width, int height) {
Canvas canvas = Canvas.createIfSupported();
canvas.setCoordinateSpaceWidth(width);
canvas.setCoordinateSpaceHeight(height);
Context2d context = canvas.getContext2d();
ImageData data = context.createImageData(width, height);
CanvasPixelArray array = data.getData();
for(int i=0; i<width*height; i++) { // ABGR
array.set(4*i+0, pixels[i] & 0xFF);
array.set(4*i+1, (pixels[i] >> 8) & 0xFF);
array.set(4*i+2, (pixels[i] >> 16) & 0xFF);
array.set(4*i+3, (pixels[i] >> 24) & 0xFF);
}
context.putImageData(data, 0, 0);
canvas.getElement().getStyle().setMargin(4, Unit.PX);
return canvas;
}
示例4: setRgb
import com.google.gwt.canvas.dom.client.ImageData; //导入依赖的package包/类
@Override public void setRgb(int startX, int startY, int width, int height,
int[] rgbArray, int offset, int scanSize) {
Context2d ctx = canvas.getContext2d();
ImageData imageData = ctx.createImageData(width, height);
CanvasPixelArray pixelData = imageData.getData();
int i = 0;
int dst = offset;
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x ++) {
int argb = rgbArray[dst + x];
pixelData.set(i++, (argb >> 16) & 255);
pixelData.set(i++, (argb >> 8) & 255);
pixelData.set(i++, (argb) & 255);
pixelData.set(i++, (argb >> 24) & 255);
}
dst += scanSize;
}
ctx.putImageData(imageData, startX, startY);
}
示例5: doPick
import com.google.gwt.canvas.dom.client.ImageData; //导入依赖的package包/类
private void doPick(int cx, int cy) {
cx/=currentScale;
cy/=currentScale;
//LogUtils.log(cx+","+cy);
ImageData data=canvas.getContext2d().getImageData(cx, cy, 1, 1);
int r=data.getRedAt(0, 0);
int g=data.getGreenAt(0, 0);
int b=data.getBlueAt(0, 0);
//LogUtils.log(r+","+g+","+b);
String hex=ColorUtils.toCssColor(r,g,b);
//LogUtils.log(hex);
colorPicker.setValue(hex);
if(backgroundList.getSelectedIndex()==3){//
updateBgStyle();
}
}
示例6: createMaskBySimilarColor
import com.google.gwt.canvas.dom.client.ImageData; //导入依赖的package包/类
/**
*
* @param data
* @param r
* @param g
* @param b
* @param maxLength
* @return imageData-width x imageData-height length (if similar value is 1,or 0)
*/
public static Uint8Array createMaskBySimilarColor(ImageData data,int r,int g,int b,int maxLength){
Uint8Array bytes=Uint8Array.createUint8(data.getWidth()*data.getHeight());
for(int y=0;y<data.getHeight();y++){
for(int x=0;x<data.getWidth();x++){
int imgR=data.getRedAt(x, y);
int imgG=data.getGreenAt(x, y);
int imgB=data.getBlueAt(x, y);
double length=ColorUtils.getColorLength(r, g, b, imgR, imgG, imgB);
if(length<maxLength){
bytes.set(y*data.getWidth()+x, 1);
}
}
}
return bytes;
}
示例7: createMaskByColor
import com.google.gwt.canvas.dom.client.ImageData; //导入依赖的package包/类
public static Uint8Array createMaskByColor(ImageData data,int r,int g,int b,boolean setSameColorCase){
Uint8Array bytes=Uint8Array.createUint8(data.getWidth()*data.getHeight());
for(int y=0;y<data.getHeight();y++){
for(int x=0;x<data.getWidth();x++){
int imgR=data.getRedAt(x, y);
int imgG=data.getGreenAt(x, y);
int imgB=data.getBlueAt(x, y);
if(r==imgR && g==imgG&&b==imgB){
if(setSameColorCase){
bytes.set(y*data.getWidth()+x, 1);
}
}else{
if(!setSameColorCase){
bytes.set(y*data.getWidth()+x, 1);
}
}
}
}
return bytes;
}
示例8: doRepreview
import com.google.gwt.canvas.dom.client.ImageData; //导入依赖的package包/类
protected void doRepreview() {
LogUtils.log("doRepreview1");
int margin=InpaintEngine.INPAINT_MARGIN;
if(maskImageElement==null){
Window.alert("no mask element");
return;
}
LogUtils.log("doRepreview1");
ImageElementUtils.copytoCanvasWithMargin(maskImageElement, sharedCanvas,true,margin,true);
Canvas grayscale=CanvasUtils.convertToGrayScale(sharedCanvas, null);
CanvasUtils.copyTo(grayscale, sharedCanvas);
ImageData maskData=CanvasUtils.getImageData(sharedCanvas);
greyScaleMaskPanel.clear();
addToPanel(greyScaleMaskPanel,maskData);
mainTab.selectTab(1);
LogUtils.log("doRepreview4");
//CanvasUtils.copyTo(maskData,sharedCanvas);
//String dataUrl=sharedCanvas.toDataUrl();
//listener.createGreyScaleMaks(maskData);
}
示例9: sourceInImageData
import com.google.gwt.canvas.dom.client.ImageData; //导入依赖的package包/类
/**
* draw only not-alpha on maskdata
* @param imageData
* @param maskData
* @return
*/
public static ImageData sourceInImageData(ImageData imageData,ImageData maskData){
//check & warn
Canvas imageCanvas=CanvasUtils.copyTo(imageData, null);
Canvas maskCanvas=CanvasUtils.copyTo(maskData, null);
Canvas canvas=CanvasUtils.copyToSizeOnly(imageCanvas, null);
canvas.getContext2d().drawImage(maskCanvas.getCanvasElement(), 0, 0);
canvas.getContext2d().setGlobalCompositeOperation(Composite.SOURCE_IN);
canvas.getContext2d().drawImage(imageCanvas.getCanvasElement(),0,0);
imageCanvas=null;
maskCanvas=null;
ImageData data=ImageDataUtils.copyFrom(canvas);
canvas=null;
return data;
}
示例10: generateImage
import com.google.gwt.canvas.dom.client.ImageData; //导入依赖的package包/类
protected void generateImage() {
int clipSX=(canvasWidth-imageWidth)/2;
int clipSY=(canvasHeight-imageHeight)/2;
int clipEX=clipSX+imageWidth;
int clipEY=clipSY+imageHeight;
ImageData data=canvas.getContext2d().getImageData(clipSX, clipSY, clipEX-clipSX, clipEY-clipSY);
CanvasUtils.createCanvas(drawCanvas, data);
String type=typeBox.getValue();
String dataUrl=drawCanvas.toDataUrl("image/"+type);
String extension=type.equals("jpeg")?"jpg":type;
String name=titleBox.getText().isEmpty()?"logo":titleBox.getText();
Anchor anchor=HTML5Download.get().generateBase64DownloadLink(dataUrl, "image/"+type, name+"."+extension, textConstants.Download(), true);
anchor.setStylePrimaryName("bt");
downloadArea.clear();
downloadArea.add(anchor);
}
示例11: jsLoadedCallback
import com.google.gwt.canvas.dom.client.ImageData; //导入依赖的package包/类
private static void jsLoadedCallback(ImageData pixels, int width, int height, int oWidth, int oHeight,
UniCallback<Image> onComplete)
{
Image image = new Image(width, height, oWidth, oHeight);
for (int x = 0; x < width; x++)
{
for (int y = 0; y < height; y++)
image.setPixel(x, y, new Color(
pixels.getRedAt(x, y) / 255f,
pixels.getGreenAt(x, y) / 255f,
pixels.getBlueAt(x, y) / 255f,
pixels.getAlphaAt(x, y) / 255f
));
}
onComplete.invoke(image);
}
示例12: measureHeight
import com.google.gwt.canvas.dom.client.ImageData; //导入依赖的package包/类
private static int measureHeight(Font font, String text) {
Canvas canvas = canvas();
Context2d ctx = canvas.getContext2d();
ctx.setFont(getFontString(font));
ctx.setFillStyle("rgb(255, 0, 0)");
int width = (int) ctx.measureText(text).getWidth();
int canvasHeight = font.getSize() * 2;
canvas.setHeight(canvasHeight + "px");
canvas.setHeight(font.getSize() * 2 + "px");
canvas.setWidth(width + "px");
ctx.fillText(text, 0, font.getSize());
ImageData data = ctx.getImageData(0, 0, width, canvasHeight);
int firstY = canvasHeight - 1;
int lastY = 0;
for (int x = 0; x < width; x++) {
for (int y = 0; y < canvasHeight; y++) {
int red = data.getRedAt(x, y);
if (red != 0) {
if (firstY > y) {
firstY = y;
}
if (lastY < y) {
lastY = y;
}
}
}
}
return lastY - firstY;
}
示例13: setUp
import com.google.gwt.canvas.dom.client.ImageData; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
userAgentUtil = Mockito.mock(UserAgentUtil.class);
canvasImageDataProvider = new CanvasImageDataProvider(userAgentUtil);
Canvas canvas = Mockito.mock(Canvas.class);
when(canvasStubView.getCanvas()).thenReturn(canvas);
Context2d context = Mockito.mock(Context2d.class);
when(canvas.getContext2d()).thenReturn(context);
ImageData imageData = Mockito.mock(ImageData.class);
when(context.getImageData(0, 0, 0, 0)).thenReturn(imageData);
}
示例14: before
import com.google.gwt.canvas.dom.client.ImageData; //导入依赖的package包/类
@Before
public void before() {
Context2d context2d = mock(Context2d.class);
imageData = mock(ImageData.class);
pixelArray = mock(CanvasPixelArray.class);
doReturn(PIXEL_VALUE).when(pixelArray)
.get(anyInt());
doReturn(pixelArray).when(imageData)
.getData();
doReturn(imageData).when(context2d)
.getImageData(anyInt(), anyInt(), anyInt(), anyInt());
instance = new CanvasImageData(context2d, WIDTH, HEIGHT);
}
示例15: setUp
import com.google.gwt.canvas.dom.client.ImageData; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
context = mock(Context2d.class);
imageData = mock(ImageData.class);
when(context.getImageData(0, 0, width, height)).thenReturn(imageData);
imageDataSlower = new CanvasImageDataSlower(context, width, height);
}