當前位置: 首頁>>代碼示例>>Java>>正文


Java Context2d.scale方法代碼示例

本文整理匯總了Java中com.google.gwt.canvas.dom.client.Context2d.scale方法的典型用法代碼示例。如果您正苦於以下問題:Java Context2d.scale方法的具體用法?Java Context2d.scale怎麽用?Java Context2d.scale使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.gwt.canvas.dom.client.Context2d的用法示例。


在下文中一共展示了Context2d.scale方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onModuleLoad

import com.google.gwt.canvas.dom.client.Context2d; //導入方法依賴的package包/類
public void onModuleLoad() {
    canvas = Canvas.createIfSupported();
    if (canvas == null) {
        Window.alert("Canvas not supported");
        return;
    }
    RootPanel.get("screen").add(canvas);

    CanvasElement el = canvas.getCanvasElement();
    el.setWidth(960);
    el.setHeight(540);

    Context2d ctx = canvas.getContext2d();
    setupContext(ctx);
    ctx.scale(3, 3);

    RootPanel.get().addDomHandler(this, KeyDownEvent.getType());

    font = new Image("images/font.png");
    fontElement = ImageElement.as(font.getElement());

    audio = Audio.createIfSupported();

    game = new Game(this);
    game.pushState(new WelcomeState(game));

    new Timer() {
        @Override
        public void run() {
            game.handleEvent();
            game.update();
            game.draw();
        }
    }.scheduleRepeating(50);
}
 
開發者ID:czak,項目名稱:retronix,代碼行數:36,代碼來源:Application.java

示例2: scaleImage

import com.google.gwt.canvas.dom.client.Context2d; //導入方法依賴的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

示例3: scaleImage

import com.google.gwt.canvas.dom.client.Context2d; //導入方法依賴的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

示例4: scaleImage

import com.google.gwt.canvas.dom.client.Context2d; //導入方法依賴的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

示例5: redraw

import com.google.gwt.canvas.dom.client.Context2d; //導入方法依賴的package包/類
public void redraw() {
	Context2d graphics2d = canvas.getContext2d();
	int w = canvas.getCoordinateSpaceWidth(), h = canvas.getCoordinateSpaceHeight();
	graphics2d.setFillStyle(background);
	graphics2d.fillRect(0, 0, w, h);
	if (pageInfo == null)
		return;

	int subsample = toSubsample(zoom);
	double scale = zoom / toZoom(subsample);
	graphics2d.save();
	int startX = w / 2 - centerX, startY = h / 2 - centerY;
	graphics2d.translate(startX, startY);
	graphics2d.scale(scale, scale);
	graphics2d.translate(-startX, -startY);
	graphics2d.scale(1, -1); // DjVu images have y-axis inverted 

	int tileSize = DjvuContext.getTileSize();
	int pw = (int) (pageInfo.width * zoom), ph = (int) (pageInfo.height * zoom);
	range.xmin = (int) (Math.max(0, centerX - w * 0.5) / tileSize / scale);
	range.xmax = (int) Math.ceil(Math.min(pw, centerX + w * 0.5) / tileSize / scale);
	range.ymin = (int) (Math.max(0, centerY - h * 0.5) / tileSize / scale);
	range.ymax = (int) Math.ceil(Math.min(ph, centerY + h * 0.5) / tileSize / scale);
	imagesArray = dataStore.getTileImages(page, subsample, range , imagesArray);
	for (int y = range.ymin; y <= range.ymax; y++) {
		for (int x = range.xmin; x <= range.xmax; x++) {
			CanvasElement canvasElement = imagesArray[y - range.ymin][x - range.xmin];
			for (int repeats = scale == 1 ? 1 : 3; repeats > 0; repeats--) {
				graphics2d.drawImage(canvasElement, startX + x * tileSize,
						-startY - y * tileSize - canvasElement.getHeight());
			}
		}
	}
	graphics2d.restore();
	// missing tile graphics may exceed the page boundary
	graphics2d.fillRect(startX + pw, 0, w, h);
	graphics2d.fillRect(0, startY + ph, w, h);

	DjvuContext.setTileRange(range, subsample);
}
 
開發者ID:mateusz-matela,項目名稱:djvu-html5,代碼行數:41,代碼來源:SinglePageLayout.java

示例6: paint

import com.google.gwt.canvas.dom.client.Context2d; //導入方法依賴的package包/類
@Override
public void paint(Canvas canvas, Matrix matrix) {
	/*
	* paint image on canvas based on the original and with the transformations of the matrix.
	* */
	Context2d context2d = canvas.getContext2d();
	context2d.save();
	boolean xReversal = matrix.getXx() < 0;
	boolean yReversal = matrix.getYy() < 0;
	context2d.scale(xReversal ? -1 : 1, yReversal ? -1 : 1);
	double xValue = xReversal ? box.getMaxX() * -1 : box.getX();
	double yValue = yReversal ? box.getMaxY() * -1 : box.getY();
	context2d.drawImage(hiddenImageCanvas.getCanvasElement(), xValue, yValue, box.getWidth(), box.getHeight());
	context2d.restore();
}
 
開發者ID:geomajas,項目名稱:geomajas-project-client-gwt2,代碼行數:16,代碼來源:CanvasImageElement.java

示例7: render

import com.google.gwt.canvas.dom.client.Context2d; //導入方法依賴的package包/類
private void render() {
    Context2d context = canvas.getContext2d();
    context.setFillStyle("white");
    context.setStrokeStyle("grey");
    context.fillRect(0, 0, 600, 600);
    context.save();
    context.translate(0, 600);
    context.scale(1, -1);
    context.scale(100, 100);
    context.setLineWidth(0.01);
    for (Body body = scene.getWorld().getBodyList(); body != null; body = body.getNext()) {
        Vec2 center = body.getPosition();
        context.save();
        context.translate(center.x, center.y);
        context.rotate(body.getAngle());
        for (Fixture fixture = body.getFixtureList(); fixture != null; fixture = fixture.getNext()) {
            Shape shape = fixture.getShape();
            if (shape.getType() == ShapeType.CIRCLE) {
                CircleShape circle = (CircleShape) shape;
                context.beginPath();
                context.arc(circle.m_p.x, circle.m_p.y, circle.getRadius(), 0, Math.PI * 2, true);
                context.closePath();
                context.stroke();
            } else if (shape.getType() == ShapeType.POLYGON) {
                PolygonShape poly = (PolygonShape) shape;
                Vec2[] vertices = poly.getVertices();
                context.beginPath();
                context.moveTo(vertices[0].x, vertices[0].y);
                for (int i = 1; i < poly.getVertexCount(); ++i) {
                    context.lineTo(vertices[i].x, vertices[i].y);
                }
                context.closePath();
                context.stroke();
            }
        }
        context.restore();
    }
    context.restore();
}
 
開發者ID:konsoletyper,項目名稱:teavm,代碼行數:40,代碼來源:BenchmarkStarter.java

示例8: draw

import com.google.gwt.canvas.dom.client.Context2d; //導入方法依賴的package包/類
@Override
public void draw(Context2d context, DisplayArea area, OnDrawnCallback cb) {
    double zoom = area.zoom();
    context.save();

    context.translate(-area.viewportLeft(), -area.viewportTop());
    context.scale(zoom, zoom);

    // outline
    int[][] coords = el.coordinates();

    context.beginPath();
    context.moveTo(coords[0][0], coords[0][1]);

    for (int i = 1; i < coords.length; i++) {
        context.lineTo(coords[i][0], coords[i][1]);
    }

    context.setLineWidth(6);
    context.stroke();
    
    context.setGlobalAlpha(0.3);
    context.setFillStyle("white");
    context.fill();
    context.setGlobalAlpha(1.0);
    
    context.closePath();

    // text
    context.setFillStyle("black");
    context.setFont("bold 60px sans-serif");
    context.setTextBaseline("top");
    context.fillText(el.text(), el.baseLeft(), el.baseTop(), el.baseWidth());

    context.restore();
    
    cb.onDrawn();
}
 
開發者ID:jhu-digital-manuscripts,項目名稱:rosa,代碼行數:39,代碼來源:TextDrawable.java

示例9: draw

import com.google.gwt.canvas.dom.client.Context2d; //導入方法依賴的package包/類
@Override
public void draw(Context2d context, DisplayArea area, OnDrawnCallback cb) {
    double zoom = area.zoom();

    context.save();

    context.translate(-area.viewportLeft(), -area.viewportTop());
    context.scale(zoom, zoom);

    context.beginPath();
    context.moveTo(coords[0][0], coords[0][1]);

    for (int i = 1; i < coords.length; i++) {
        context.lineTo(coords[i][0], coords[i][1]);
    }

    context.setLineWidth(6);
    context.stroke();
    
    context.setGlobalAlpha(0.3);
    context.setFillStyle("white");
    context.fill();
    context.setGlobalAlpha(1.0);
    
    context.closePath();

    context.restore();
    
    cb.onDrawn();
}
 
開發者ID:jhu-digital-manuscripts,項目名稱:rosa,代碼行數:31,代碼來源:PolygonDrawable.java

示例10: paintToCanvas

import com.google.gwt.canvas.dom.client.Context2d; //導入方法依賴的package包/類
/**
 * Paints the given page of the given {@link Layout} at the given zoom level
 * into the given {@link CanvasElement}, which is resized to include the whole page.
 * The size in pixel is also returned.
 */
public static Size2i paintToCanvas(Layout layout, int pageIndex, float zoom,
																	 com.google.gwt.canvas.client.Canvas canvas) {
	Context2d context = canvas.getContext2d();

	//compute size
	Page page = layout.getPages().get(pageIndex);
	Size2f pageSize = page.getFormat().getSize();
	int width = Units.mmToPxInt(pageSize.width, zoom);
	int height = Units.mmToPxInt(pageSize.height, zoom);

	//resize canvas and coordinate space
	canvas.setWidth(width + "px");
	canvas.setHeight(height + "px");
	int coordSpaceFactor = 2; //double resolution: smoother
	canvas.setCoordinateSpaceWidth(width * coordSpaceFactor);
	canvas.setCoordinateSpaceHeight(height * coordSpaceFactor);
	context.scale(coordSpaceFactor, coordSpaceFactor);

	//white page
   context.setFillStyle("white");
   context.fillRect(0, 0, width, height);

   //paint layout
	LayoutRenderer.paintToCanvas(layout, pageIndex, zoom, origin,
		new GwtCanvas(context, CanvasFormat.Raster,
			CanvasDecoration.Interactive, CanvasIntegrity.Perfect));

	return new Size2i(width, height);
}
 
開發者ID:Xenoage,項目名稱:Zong,代碼行數:35,代碼來源:GwtCanvasLayoutRenderer.java

示例11: draw

import com.google.gwt.canvas.dom.client.Context2d; //導入方法依賴的package包/類
@Override
public void draw(Context2d context, DisplayArea area, OnDrawnCallback cb) {
	double zoom = area.zoom();
	context.save();
	
	context.translate(-area.viewportLeft(), -area.viewportTop());
	context.scale(zoom, zoom);
	
	// Draw outline
	int[][] coords = el.coordinates();
	
	context.beginPath();
	context.moveTo(coords[0][0], coords[0][1]);
	
	for (int i = 1; i < coords.length; i++) {
		context.lineTo(coords[i][0], coords[i][1]);
	}
	
	context.setLineWidth(6);
	context.stroke();
	
	context.setGlobalAlpha(0.3);
	context.setFillStyle("white");
	context.fill();
	context.setGlobalAlpha(1.0);
	
	context.closePath();
	
	// Write text
	context.setFillStyle("black");
	context.setFont("bold 60px sans-serif");
	context.setTextBaseline("top");
	
	if (el.text().contains("<") && el.text().contains(">")) {
		context.fillText(el.label() + "...", el.baseLeft(), el.baseTop(), el.baseWidth());
		el.neverShowPopup(false);
	} else {
		String[] words = el.text().split(" ");
		String line = "";
		
		int y = el.baseTop();
		
		for (int i = 0; i < words.length; i++) {
			String test_line = line + words[i] + " ";
			
			if (context.measureText(test_line).getWidth() > el.baseWidth() && i > 0
					|| words[i].contains("\n")) {
				context.fillText(line, el.baseLeft(), y);
				y += step;
				line = words[i] + " ";
				
				if (y + step > el.baseTop() + el.baseHeight()) {
    				context.restore();
    				el.neverShowPopup(false);
    				cb.onDrawn();
    				return;
    			}
			} else {
				line = test_line;
			}
		}
		context.fillText(line, el.baseLeft(), y);
		el.neverShowPopup(true);
	}
	context.restore();
	
	cb.onDrawn();
}
 
開發者ID:jhu-digital-manuscripts,項目名稱:rosa,代碼行數:69,代碼來源:MultiLineTextDrawable.java


注:本文中的com.google.gwt.canvas.dom.client.Context2d.scale方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。