Java Code Examples for com.google.gwt.canvas.dom.client.Context2d#drawImage()
The following examples show how to use
com.google.gwt.canvas.dom.client.Context2d#drawImage() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DataStore.java From djvu-html5 with GNU General Public License v2.0 | 6 votes |
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); }
Example 2
Source File: MaterialCameraCapture.java From gwt-material-addins with Apache License 2.0 | 5 votes |
/** * Native call to capture the frame of the video stream. */ protected String nativeCaptureToDataURL(CanvasElement canvas, Element element, String mimeType) { VideoElement videoElement = (VideoElement) element; int width = videoElement.getVideoWidth(); int height = videoElement.getVideoHeight(); if (Double.isNaN(width) || Double.isNaN(height)) { width = videoElement.getClientWidth(); height = videoElement.getClientHeight(); } canvas.setWidth(width); canvas.setHeight(height); Context2d context = canvas.getContext2d(); context.drawImage(videoElement, 0, 0, width, height); return canvas.toDataUrl(mimeType); }
Example 3
Source File: SinglePageLayout.java From djvu-html5 with GNU General Public License v2.0 | 5 votes |
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); }