本文整理匯總了Java中com.google.gwt.canvas.dom.client.Context2d.drawImage方法的典型用法代碼示例。如果您正苦於以下問題:Java Context2d.drawImage方法的具體用法?Java Context2d.drawImage怎麽用?Java Context2d.drawImage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.gwt.canvas.dom.client.Context2d
的用法示例。
在下文中一共展示了Context2d.drawImage方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: drawGridOn
import com.google.gwt.canvas.dom.client.Context2d; //導入方法依賴的package包/類
public static void drawGridOn(Context2d context2d) {
if (gridCanvas == null) {
gridCanvas = Canvas.createIfSupported();
gridCanvas.setCoordinateSpaceWidth(3000);
gridCanvas.setCoordinateSpaceHeight(2000);
int width = gridCanvas.getCoordinateSpaceWidth();
int height = gridCanvas.getCoordinateSpaceHeight();
Context2d backgroundContext = gridCanvas.getContext2d();
backgroundContext.setStrokeStyle(Converter.convert(ColorOwn.BLACK.transparency(Transparency.SELECTION_BACKGROUND)));
for (int i = 0; i < width; i += SharedConstants.DEFAULT_GRID_SIZE) {
drawLine(backgroundContext, i, 0, i, height);
}
for (int i = 0; i < height; i += SharedConstants.DEFAULT_GRID_SIZE) {
drawLine(backgroundContext, 0, i, width, i);
}
}
context2d.drawImage(gridCanvas.getCanvasElement(), 0, 0);
}
示例2: setTile
import com.google.gwt.canvas.dom.client.Context2d; //導入方法依賴的package包/類
public void setTile(TileInfo tileInfo, GMap bufferGMap) {
if (bufferImageData == null || bufferImageData.getWidth() != bufferGMap.getDataWidth()
|| bufferImageData.getHeight() != bufferGMap.getDataHeight()) {
bufferImageData = bufferCanvas.getContext2d()
.createImageData(bufferGMap.getDataWidth(), bufferGMap.getDataHeight());
}
Uint8Array imageArray = bufferImageData.getData().cast();
imageArray.set(bufferGMap.getImageData());
bufferCanvas.getContext2d().putImageData(bufferImageData, -bufferGMap.getBorder(), 0);
CanvasElement tile = tiles.get(tileInfo);
if (tile == null) {
tile = createImage(bufferGMap.getDataWidth() - bufferGMap.getBorder(), bufferGMap.getDataHeight());
tiles.put(new TileInfo(tileInfo), tile);
}
Context2d c = tile.getContext2d();
c.setFillStyle("white");
c.fillRect(0, 0, tileSize, tileSize);
c.drawImage(bufferCanvas, 0, 0);
for (Consumer<Integer> listener : tileListeners)
listener.accept(tileInfo.page);
}
示例3: render
import com.google.gwt.canvas.dom.client.Context2d; //導入方法依賴的package包/類
public void render() {
Context2d ctx = bufferedCanvas.getContextBuffer();
if (updateBuffer) {
bufferedCanvas.clearBuffer();
ImageElement imageElement = activeTileset.getImgElement();
if (imageElement != null) {
ctx.drawImage(imageElement, 0, 0);
}
ctx.drawImage(highlight.getContext().getCanvas(), 0, 0);
// Grid
ctx.drawImage(grid.getContext().getCanvas(), 0, 0);
updateBuffer = false;
}
bufferedCanvas.flushBuffer();
}
示例4: draw
import com.google.gwt.canvas.dom.client.Context2d; //導入方法依賴的package包/類
public void draw() {
int tileSize = tileset.getTileSize();
int tilesInRow = tileset.getTilesX();
ImageElement img = tileset.getImgElement();
canvasLayer.clear();
Context2d ctx = canvasLayer.getContext();
for (int i = 0; i < data.length; i++) {
int x = i * tileSize;
for (int j = 0; j < data[i].length; j++) {
int y = j * tileSize;
int tile = data[i][j];
if (tile != -1) {
int tileX = tile % tilesInRow * tileSize;
int tileY = tile / tilesInRow * tileSize;
ctx.drawImage(img, tileX, tileY, tileSize, tileSize, x, y, tileSize, tileSize);
}
}
}
needRedraw = false;
}
示例5: draw
import com.google.gwt.canvas.dom.client.Context2d; //導入方法依賴的package包/類
public void draw(Context2d context, int x, int y, double scaling)
{
if( !m_loaded ) return;
int m = m_frame % m_framesAcross;
int n = (m_frame) / m_framesAcross;
int offsetX = m * m_frameWidth;
int offsetY = n * m_frameHeight;
int widthScaled = (int) (m_frameWidth * scaling);
int heightScaled = (int) (m_frameHeight * scaling);
x -= widthScaled/2;
y -= heightScaled/2;
// s_logger.severe(m_frame + " " + m + " " + n);
context.drawImage(m_image, offsetX, offsetY, m_frameWidth, m_frameHeight, x, y, widthScaled, heightScaled);
}
示例6: ZoomAnimation
import com.google.gwt.canvas.dom.client.Context2d; //導入方法依賴的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;
}
示例7: 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;
}
示例8: 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;
}
示例9: 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;
}
示例10: drawOn
import com.google.gwt.canvas.dom.client.Context2d; //導入方法依賴的package包/類
public void drawOn(Context2d context, boolean isSelected) {
if (redrawNecessary || lastSelected != isSelected) {
redrawNecessary = false;
CanvasElement el = canvas.getCanvasElement();
canvas.getContext2d().clearRect(0, 0, el.getWidth(), el.getHeight());
canvas.getCanvasElement().setWidth(rect.getWidth() + 1); // canvas size is +1px to make sure a rectangle with width pixels is still visible (in Swing the bound-checking happens in BaseDrawHandlerSwing because you cannot extend the clipping area)
canvas.getCanvasElement().setHeight(rect.getHeight() + 1);
drawer.drawAll(isSelected);
if (isSelected) {
metadrawer.drawAll();
}
}
lastSelected = isSelected;
context.drawImage(canvas.getCanvasElement(), element.getRectangle().getX(), element.getRectangle().getY());
}
示例11: 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);
}
示例12: drawImage
import com.google.gwt.canvas.dom.client.Context2d; //導入方法依賴的package包/類
protected void drawImage(
ImageElement image, Context2d context, int row, int column, double scale) {
int width = (int) (image.getWidth() * scale);
int height = (int) (image.getHeight() * scale);
int xOffset = (cellWidth - width) / 2;
int yOffset = (cellHeight - height) / 2;
context.drawImage(image, column * cellWidth + xOffset, row * cellHeight + yOffset,
width, height);
}
示例13: 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();
}
示例14: draw
import com.google.gwt.canvas.dom.client.Context2d; //導入方法依賴的package包/類
public void draw(Context2d context) {
context.drawImage(ctx.getCanvas(), 0, 0);
//ctx.drawImage(context.getCanvas(), 0, 0);
}
示例15: update
import com.google.gwt.canvas.dom.client.Context2d; //導入方法依賴的package包/類
public void update(UpdateConfig config)
{
clear();
Context2d context = m_canvas.getContext2d();
Context2d stageContext = m_stagingCanvas.getContext2d();
double cellSize = config.cellSize;
cellSize -= m_pinch*2;
double cellSize_div2 = cellSize/2;
int limit_n = config.startN + config.down;
int limit_m = config.startM + config.across;
boolean foundFirstCell = false;
//
for( int n = config.startN; n < limit_n; n++ )
{
for( int m = config.startM; m < limit_m; m++ )
{
int skip = m_skipper.skip(m, n);
if( skip == 1 )
{
continue;
}
else if( skip > 1 )
{
m += skip;
m -= 1; // will get incremented in for loop so offsetting here.
continue;
}
int index = n*config.totalGridSize + m;
if( !config.ownership.isSet(index) ) continue;
int offsetM = m - config.startM_meta;
int offsetN = n - config.startN_meta;
int offsetM_mod = offsetM % config.metaSubCellCount;
int offsetN_mod = offsetN % config.metaSubCellCount;
offsetM -= offsetM_mod;
offsetN -= offsetN_mod;
offsetM /= config.metaSubCellCount;
offsetN /= config.metaSubCellCount;
double currX = config.startX_meta + offsetM * config.metaCellSize + offsetM_mod * config.cellSizePlusPadding;
double currY = config.startY_meta + offsetN * config.metaCellSize + offsetN_mod * config.cellSizePlusPadding;
currX += m_pinch;
currY += m_pinch;
if( !foundFirstCell )
{
stageContext.fillRect(0, 0, cellSize, cellSize);
if( m_animation != null )
{
m_animation.draw(stageContext, (int)cellSize_div2, (int)cellSize_div2, config.scaling);
}
foundFirstCell = true;
}
context.drawImage(m_stagingCanvasElement, 0, 0, cellSize, cellSize, currX, currY, cellSize, cellSize);
m_clear = false;
}
}
m_animation.update(config.timestep);
}