当前位置: 首页>>代码示例>>Java>>正文


Java Canvas.getContext2d方法代码示例

本文整理汇总了Java中com.google.gwt.canvas.client.Canvas.getContext2d方法的典型用法代码示例。如果您正苦于以下问题:Java Canvas.getContext2d方法的具体用法?Java Canvas.getContext2d怎么用?Java Canvas.getContext2d使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.gwt.canvas.client.Canvas的用法示例。


在下文中一共展示了Canvas.getContext2d方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createCanvas

import com.google.gwt.canvas.client.Canvas; //导入方法依赖的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;
	
}
 
开发者ID:npedotnet,项目名称:npe-image-library,代码行数:25,代码来源:GwtImageReader.java

示例2: createImageCanvas

import com.google.gwt.canvas.client.Canvas; //导入方法依赖的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;

	}
 
开发者ID:npedotnet,项目名称:TGAReader,代码行数:22,代码来源:TexturedCube.java

示例3: createImageCanvas

import com.google.gwt.canvas.client.Canvas; //导入方法依赖的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;
	
}
 
开发者ID:npedotnet,项目名称:TGAReader,代码行数:24,代码来源:ImageCanvasTest.java

示例4: TextDisplayElement

import com.google.gwt.canvas.client.Canvas; //导入方法依赖的package包/类
public TextDisplayElement(String id, int x, int y, int width, int height,
        String text, int[][] coords) {
    super(id, x, y, width, height);
    this.coords = coords;
    this.text = text;
    
 // Create a canvas containing the filled polygon with no border
    Canvas sub_canvas = Canvas.createIfSupported();
    sub_canvas.setCoordinateSpaceWidth(width);
    sub_canvas.setCoordinateSpaceHeight(height);
    
    Context2d context = sub_canvas.getContext2d();
    context.beginPath();
    context.moveTo(coords[0][0] - baseLeft(), coords[0][1] - baseTop());

    for (int i = 1; i < coords.length; i++) {
    	context.lineTo(coords[i][0] - baseLeft(), coords[i][1] - baseTop());
    }
	
    context.setFillStyle(color_fill);
    context.fill();
    
    context.closePath();
    
    this.image_data = context.getImageData(0, 0, width, height);
}
 
开发者ID:jhu-digital-manuscripts,项目名称:rosa,代码行数:27,代码来源:TextDisplayElement.java

示例5: createBillboard

import com.google.gwt.canvas.client.Canvas; //导入方法依赖的package包/类
public static BillboardOptions createBillboard(DrawInteractionOptions options) {
    Canvas canvas = Canvas.createIfSupported();
    Context2d context = canvas.getContext2d();

    context.setFillStyle(options.color.toCssColorString());
    context.setStrokeStyle(options.outlineColor.toCssColorString());
    context.setLineWidth(options.outlineWidth);

    context.translate(canvas.getCoordinateSpaceWidth() / 2, canvas.getCoordinateSpaceHeight() / 2);
    context.beginPath();
    context.arc(0, 0, options.pixelSize, 0, Math.PI * 2, true);
    context.closePath();
    context.stroke();
    context.fill();

    BillboardOptions billboard = new BillboardOptions();
    billboard.horizontalOrigin = HorizontalOrigin.CENTER();
    billboard.verticalOrigin = VerticalOrigin.CENTER();
    billboard.imageCanvas = canvas.getCanvasElement();
    return billboard;
}
 
开发者ID:iSergio,项目名称:gwt-cs,代码行数:22,代码来源:MarkerGroup.java

示例6: onModuleLoad

import com.google.gwt.canvas.client.Canvas; //导入方法依赖的package包/类
/**
 * Initializes the receiver application and game objects, and starts the
 * receiver.
 */
@Override
public void onModuleLoad()
{
	Canvas canvas = Canvas.createIfSupported();
	canvas.getCanvasElement().setId("board");
	canvas.addStyleName("canvas");

	RootPanel.get().add(canvas);

	Context2d context = canvas.getContext2d();
	context.getCanvas().setWidth(Window.getClientWidth());
	context.getCanvas().setHeight(Window.getClientHeight());
	Board mBoard = new Board(context);

	String appId = "ce2ad55e-2181-44bb-b5e7-9e65e0510d86";
	ArrayList<String> protocol = new ArrayList<String>(1);
	protocol.add(PROTOCOL);

	Receiver chromecastApp = Receiver.create(appId, protocol,
			JavaScriptObject.createObject(), 5);

	mBoard.clear();
	mBoard.drawGrid();

	TicTacToe gameEngine = new TicTacToe(mBoard);
	gameEngine.mChannelHandler.addChannelFactory(chromecastApp
			.createChannelFactory(PROTOCOL));
	chromecastApp.start();
}
 
开发者ID:imarvelapps,项目名称:GWTChromeCast,代码行数:34,代码来源:TicTacToeApp.java

示例7: ZoomAnimation

import com.google.gwt.canvas.client.Canvas; //导入方法依赖的package包/类
/**
 * Animate zoom and tranlate on the HTML5 canvas, after the DisplayArea has zoomed in.
 * 
 * @param context
 * @param canvas_img
 * 			the CanvasElement of the canvas to be animated
 * @param cb
 * 			callback for when the animation completes
 * @param old_width
 * 			the width of the viewport before zoom
 * @param new_width
 * 			the width of the viewport after zoom, in the same coordinates as old_width
 * @param new_x
 * 			x coordinate of the new viewport center, relative to the HTML5 canvas 
 * 			in the browser
 * @param new_y
 * 			y coordinate of the new viewport center, relative to the HTML5 canvas
 * 			in the browser
 */
public ZoomAnimation(Context2d context, CanvasElement canvas_img,
		AnimationCallback cb, int old_width, int new_width, int new_x, int new_y) {
	this.context = context;
	
	Canvas buffer = Canvas.createIfSupported();
	Context2d buff_context = buffer.getContext2d();
	
	buffer.setPixelSize(canvas_img.getWidth(), canvas_img.getHeight());
	buffer.setCoordinateSpaceWidth(canvas_img.getWidth());
	buffer.setCoordinateSpaceHeight(canvas_img.getHeight());
	
	buff_context.drawImage(canvas_img, 0, 0);
	
	this.canvas_img = buff_context.getCanvas();
	
	scale = (double) old_width / new_width;
	
	this.width_from = canvas_img.getWidth();
	this.height_from = canvas_img.getHeight();
	
	this.x_from = width_from / 2;
	this.y_from = height_from / 2;
	
	this.x_to = new_x;
	this.y_to = new_y;
	
	this.cb = cb;
}
 
开发者ID:jhu-digital-manuscripts,项目名称:rosa,代码行数:48,代码来源:ZoomAnimation.java

示例8: MultiLineTextDisplayElement

import com.google.gwt.canvas.client.Canvas; //导入方法依赖的package包/类
public MultiLineTextDisplayElement(String id, int x, int y, int width, int height,
        String text, String label, int[][] coords) {
    super(id, x, y, width, height);
    this.coords = coords;
    this.label = label;
    this.text = text;
    
    popup = new PopupPanel(true, false);
    HTML content = new HTML(text);
	
    popup.setStylePrimaryName("PopupPanel");
    popup.addStyleName("AnnotationPopup");
	popup.setWidget(content);
    
 // Create a canvas containing the filled polygon with no border
    Canvas sub_canvas = Canvas.createIfSupported();
    sub_canvas.setCoordinateSpaceWidth(width);
    sub_canvas.setCoordinateSpaceHeight(height);
    
    Context2d context = sub_canvas.getContext2d();
    context.beginPath();
    context.moveTo(coords[0][0] - baseLeft(), coords[0][1] - baseTop());

    for (int i = 1; i < coords.length; i++) {
    	context.lineTo(coords[i][0] - baseLeft(), coords[i][1] - baseTop());
    }
	
    context.setFillStyle(color_fill);
    context.fill();
    
    context.closePath();
    
    this.image_data = context.getImageData(0, 0, width, height);
}
 
开发者ID:jhu-digital-manuscripts,项目名称:rosa,代码行数:35,代码来源:MultiLineTextDisplayElement.java

示例9: PolygonDisplayElement

import com.google.gwt.canvas.client.Canvas; //导入方法依赖的package包/类
public PolygonDisplayElement(String id, int x, int y, int width,
        int height, int[][] coords) {
    super(id, x, y, width, height);
    this.coords = coords;
    
    // Create a canvas containing the filled polygon with no border
    Canvas sub_canvas = Canvas.createIfSupported();
    sub_canvas.setCoordinateSpaceWidth(baseWidth());
    sub_canvas.setCoordinateSpaceHeight(baseHeight());
    
    Context2d context = sub_canvas.getContext2d();
    
    context.save();
    context.beginPath();
    context.moveTo(coords[0][0] - baseLeft(), coords[0][1] - baseTop());
    
    for (int i = 1; i < coords.length; i++) {
    	context.lineTo(coords[i][0] - baseLeft(), coords[i][1] - baseTop());
    }
    
    context.setFillStyle(fill_color);
    context.fill();
    
	context.closePath();
	
    context.restore();
    
    this.image_data = context.getImageData(0, 0, baseWidth(), baseHeight());
}
 
开发者ID:jhu-digital-manuscripts,项目名称:rosa,代码行数:30,代码来源:PolygonDisplayElement.java

示例10: measureHeight

import com.google.gwt.canvas.client.Canvas; //导入方法依赖的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;
}
 
开发者ID:JetBrains,项目名称:jetpad-projectional-open-source,代码行数:33,代码来源:TextMetricsCalculator.java

示例11: scaleImage

import com.google.gwt.canvas.client.Canvas; //导入方法依赖的package包/类
private ImageData scaleImage(Image image, double scaleToRatio) {
    Canvas canvasTmp = Canvas.createIfSupported();
    Context2d context = canvasTmp.getContext2d();

    int imageHeight = image.getHeight();

    double ch = (imageHeight * scaleToRatio);
    int imageWidth = image.getWidth();
    
    double cw = (imageWidth * scaleToRatio);

    canvasTmp.setCoordinateSpaceHeight((int) ch);
    canvasTmp.setCoordinateSpaceWidth((int) cw);

    // TODO: make a temp imageElement?
    ImageElement imageElement = ImageElement.as(image.getElement());

    // s = source
    // d = destination
    double sx = 0;
    double sy = 0;
    int imageElementWidth = imageElement.getWidth();
    if (imageElementWidth <= 0) {
        imageElementWidth = imageWidth;
    }
    double sw = imageElementWidth;
    int imageElementHeight = imageElement.getHeight();
    if (imageElementHeight <= 0) {
        imageElementHeight = imageHeight;
    }
    double sh = imageElementHeight;

    double dx = 0;
    double dy = 0;
    double dw = imageElementWidth;
    double dh = imageElementHeight;

    // tell it to scale image
    context.scale(scaleToRatio, scaleToRatio);

    // draw image to canvas
    context.drawImage(imageElement, sx, sy, sw, sh, dx, dy, dw, dh);

    // get image data
    double w = dw * scaleToRatio;
    double h = dh * scaleToRatio;
    ImageData imageData = null;
    try {
        imageData = context.getImageData(0, 0, w, h);
    } catch (Exception e) {
        // no image data. we'll try againg...
        String b = e.getLocalizedMessage();
    }

    int ht = (int) h + 10;
    int wt = (int) w + 10;
    
    // Clear the div, clear the drawing canvas then reinsert.  Otherwise, ghosts of the previous image appear.
    canvasDiv.clear();
            
    imageCanvasContext.clearRect(0, 0, imageCanvas.getCoordinateSpaceWidth(), imageCanvas.getCoordinateSpaceHeight());
    
    canvasDiv.add(imageCanvas, 0, 0);
    canvasDiv.add(drawingCanvas, 0, 0);
    
    imageCanvas.setCoordinateSpaceHeight(ht);
    imageCanvas.setCoordinateSpaceWidth(wt);
    
    drawingCanvas.setCoordinateSpaceHeight(ht);
    drawingCanvas.setCoordinateSpaceWidth(wt);
    
    canvasDiv.setSize(wt + "px", ht + "px");

    return imageData;
}
 
开发者ID:NOAA-PMEL,项目名称:LAS,代码行数:76,代码来源:OutputPanel.java

示例12: scaleImage

import com.google.gwt.canvas.client.Canvas; //导入方法依赖的package包/类
private ImageData scaleImage(double scaleToRatio) {
	Canvas canvasTmp = Canvas.createIfSupported();
	Context2d context = canvasTmp.getContext2d();

	int imageHeight = plotImage.getHeight();
	double ch = (imageHeight * scaleToRatio);
	int imageWidth = plotImage.getWidth();
	double cw = (imageWidth * scaleToRatio);
	
	if ( imageHeight <= 0 || imageWidth <=0 ) {
	    return null;
	}

	canvasTmp.setCoordinateSpaceHeight((int) ch);
	canvasTmp.setCoordinateSpaceWidth((int) cw);

	// TODO: make a temp imageElement?
	ImageElement imageElement = ImageElement.as(plotImage.getElement());

	// s = source
	// d = destination
	double sx = 0;
	double sy = 0;
	int imageElementWidth = imageElement.getWidth();
	if (imageElementWidth <= 0) {
		imageElementWidth = imageWidth;
	}
	double sw = imageElementWidth;
	int imageElementHeight = imageElement.getHeight();
	if (imageElementHeight <= 0) {
		imageElementHeight = imageHeight;
	}
	double sh = imageElementHeight;

	double dx = 0;
	double dy = 0;
	double dw = imageElementWidth;
	double dh = imageElementHeight;

	// tell it to scale image
	context.scale(scaleToRatio, scaleToRatio);

	// draw image to canvas
	context.drawImage(imageElement, sx, sy, sw, sh, dx, dy, dw, dh);

	// get image data
	double w = dw * scaleToRatio;
	double h = dh * scaleToRatio;
	ImageData imageData = null;
	try {
		imageData = context.getImageData(0, 0, w, h);
	} catch (Exception e) {
		// Well bummer
	}
       int ht = (int) h + 10;
       int wt = (int) w + 10;
       
       // Clear the div, clear the drawing canvas then reinsert.  Otherwise, ghosts of the previous image appear.
       canvasDiv.clear();
               
       imageCanvasContext.clearRect(0, 0, imageCanvas.getCoordinateSpaceWidth(), imageCanvas.getCoordinateSpaceHeight());
       
       canvasDiv.add(imageCanvas, 0, 0);
       canvasDiv.add(drawingCanvas, 0, 0);
       
	imageCanvas.setCoordinateSpaceHeight(ht);
	imageCanvas.setCoordinateSpaceWidth(wt);
	drawingCanvas.setCoordinateSpaceHeight(ht);
	drawingCanvas.setCoordinateSpaceWidth(wt);
	canvasDiv.setSize(wt + "px", ht + "px");

	return imageData;
}
 
开发者ID:NOAA-PMEL,项目名称:LAS,代码行数:74,代码来源:Correlation.java

示例13: scaleImage

import com.google.gwt.canvas.client.Canvas; //导入方法依赖的package包/类
private ImageData scaleImage(double scaleToRatio) {
    Canvas canvasTmp = Canvas.createIfSupported();
    Context2d context = canvasTmp.getContext2d();

    int imageHeight = plotImage.getHeight();
    double ch = (imageHeight * scaleToRatio);
    int imageWidth = plotImage.getWidth();
    double cw = (imageWidth * scaleToRatio);

    canvasTmp.setCoordinateSpaceHeight((int) ch);
    canvasTmp.setCoordinateSpaceWidth((int) cw);

    // TODO: make a temp imageElement?
    ImageElement imageElement = ImageElement.as(plotImage.getElement());

    // s = source
    // d = destination
    double sx = 0;
    double sy = 0;
    int imageElementWidth = imageElement.getWidth();
    if (imageElementWidth <= 0) {
        imageElementWidth = imageWidth;
    }
    double sw = imageElementWidth;
    int imageElementHeight = imageElement.getHeight();
    if (imageElementHeight <= 0) {
        imageElementHeight = imageHeight;
    }
    double sh = imageElementHeight;

    double dx = 0;
    double dy = 0;
    double dw = imageElementWidth;
    double dh = imageElementHeight;

    // tell it to scale image
    context.scale(scaleToRatio, scaleToRatio);

    // draw image to canvas
    context.drawImage(imageElement, sx, sy, sw, sh, dx, dy, dw, dh);

    // get image data
    double w = dw * scaleToRatio;
    double h = dh * scaleToRatio;
    ImageData imageData = null;
    try {
        imageData = context.getImageData(0, 0, w, h);
    } catch (Exception e) {
        // well, bummer
    }

    int ht = (int) h + 10;
    int wt = (int) w + 10;
         
    // Clear the div, clear the drawing canvas then reinsert. Otherwise, ghosts of the previous image appear.
    canvasDiv.clear();
            
    imageCanvasContext.clearRect(0, 0, imageCanvas.getCoordinateSpaceWidth(), imageCanvas.getCoordinateSpaceHeight());
    
    canvasDiv.add(imageCanvas, 0, 0);
    canvasDiv.add(drawingCanvas, 0, 0);
    
    imageCanvas.setCoordinateSpaceHeight(ht);
    imageCanvas.setCoordinateSpaceWidth(wt);
    
    drawingCanvas.setCoordinateSpaceHeight(ht);
    drawingCanvas.setCoordinateSpaceWidth(wt);
    
    
    canvasDiv.setSize(wt+"px", ht+"px");
    
    return imageData;
}
 
开发者ID:NOAA-PMEL,项目名称:LAS,代码行数:74,代码来源:SimplePropPropViewer.java

示例14: draw

import com.google.gwt.canvas.client.Canvas; //导入方法依赖的package包/类
private static void draw(CanvasElement el, String idcode, String coordinates)
{
    Canvas canvas = Canvas.wrap(el);
    if (idcode != null && idcode.length() > 0) {
        String combined = idcode + (coordinates != null ? " " + coordinates : "");
        Context2d ctx = canvas.getContext2d();
        drawMolecule(ctx, combined,
            canvas.getCoordinateSpaceWidth(), canvas.getCoordinateSpaceHeight());
    }
}
 
开发者ID:cheminfo,项目名称:openchemlib-js,代码行数:11,代码来源:StructureView.java

示例15: drawIDCode

import com.google.gwt.canvas.client.Canvas; //导入方法依赖的package包/类
public static void drawIDCode(CanvasElement el, String idcode, String coordinates, int displayMode,String[] atomText)
{
    Canvas canvas = Canvas.wrap(el);
    if (idcode != null && idcode.length() > 0) {
        String combined = idcode + (coordinates != null ? " " + coordinates : "");
        Context2d ctx = canvas.getContext2d();
        drawMolecule(ctx, combined,
                canvas.getCoordinateSpaceWidth(),
                canvas.getCoordinateSpaceHeight(),
                displayMode,atomText);
    }
}
 
开发者ID:cheminfo,项目名称:openchemlib-js,代码行数:13,代码来源:StructureView.java


注:本文中的com.google.gwt.canvas.client.Canvas.getContext2d方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。