List of usage examples for com.google.gwt.canvas.dom.client ImageData getRedAt
public final int getRedAt(int x, int y)
From source file:jetbrains.jetpad.projectional.domUtil.TextMetricsCalculator.java
License:Apache License
private static int measureHeight(Font font, String text) { Canvas canvas = canvas();/*from w w w .ja v a 2 s. c om*/ 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; }
From source file:nl.mpi.tg.eg.experiment.client.view.ColourPickerCanvasView.java
License:Open Source License
private void setColour(int x, int y, Canvas targetCanvas, VerticalPanel targetPanel) { x = (x >= targetCanvas.getCoordinateSpaceWidth()) ? targetCanvas.getCoordinateSpaceWidth() - 1 : x; y = (y >= targetCanvas.getCoordinateSpaceHeight()) ? targetCanvas.getCoordinateSpaceHeight() - 1 : y; final ImageData imageData = targetCanvas.getContext2d().getImageData(x, y, 1, 1); final int blue = imageData.getBlueAt(0, 0); final int green = imageData.getGreenAt(0, 0); final int red = imageData.getRedAt(0, 0); if (targetPanel.equals(selectedColourPanel)) { selectedColourData = new ColourData(red, green, blue); }//www . ja v a 2 s .c om targetPanel.getElement().setAttribute("style", "background:rgb(" + red + "," + green + "," + blue + ")"); }
From source file:nl.mpi.tg.eg.experiment.client.view.ColourPickerCanvasView.java
License:Open Source License
private void setHue(int x, int y, Canvas targetCanvas) { x = (x >= targetCanvas.getCoordinateSpaceWidth()) ? targetCanvas.getCoordinateSpaceWidth() - 1 : x; y = (y >= targetCanvas.getCoordinateSpaceHeight()) ? targetCanvas.getCoordinateSpaceHeight() - 1 : y; final ImageData imageData = targetCanvas.getContext2d().getImageData(x, y, 1, 1); final int blue = imageData.getBlueAt(0, 0); final int green = imageData.getGreenAt(0, 0); final int red = imageData.getRedAt(0, 0); setHue(red, green, blue);//from www . ja v a 2 s . c om }