/** * Returns the red value at position (x,y). * * @param x the x coordinate * @param y the y coordinate * @return the red value at position (x,y), or 0 if not in the image * @see #setRedAt(int, int, int) * @see #getColorAt(int, int, int) */ public final int getRedAt(int x, int y) { return getColorAt(x, y, OFFSET_RED); }
/** * Sets the blue value at position (x,y). * * @param blue the blue value * @param x the x coordinate * @param y the y coordinate * @see #getBlueAt(int, int) * @see #getColorAt(int, int, int) */ public final void setBlueAt(int blue, int x, int y) { setColorAt(blue, x, y, OFFSET_BLUE); }
private String getColorAtPixel(final int x, final int y) { final int fixedX = Math.max(Math.min(x, 179), 0); final int fixedy = Math.max(Math.min(y, 179), 0); final Context2d ctx = canvas.getContext2d(); final ImageData imageData = ctx.getImageData(fixedX, fixedy, 1, 1); final CanvasPixelArray data = imageData.getData(); return Colors.rgb2html(new Rgb(data.get(0), data.get(1), data.get(2))); }
private static void jsLoadedCallback(ImageData pixels, int width, int height, int oWidth, int oHeight, UniCallback<Image> onComplete) { Image image = new Image(width, height, oWidth, oHeight); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) image.setPixel(x, y, new Color( pixels.getRedAt(x, y) / 255f, pixels.getGreenAt(x, y) / 255f, pixels.getBlueAt(x, y) / 255f, pixels.getAlphaAt(x, y) / 255f )); } onComplete.invoke(image); }
imagedata.getData().set( index , (int)(Math.sqrt( pixelColor.getR() ) * 255) ); imagedata.getData().set( index + 1 , (int)(Math.sqrt( pixelColor.getG() ) * 255) ); imagedata.getData().set( index + 2 , (int)(Math.sqrt( pixelColor.getB() ) * 255) ); imagedata.getData().set( index + 3 , 255 ); // alpha
@Override public void setRgb(int startX, int startY, int width, int height, int[] rgbArray, int offset, int scanSize) { Context2d ctx = canvas.getContext2d(); ImageData imageData = ctx.createImageData(width, height); CanvasPixelArray pixelData = imageData.getData(); int i = 0; int dst = offset; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x ++) { int argb = rgbArray[dst + x]; pixelData.set(i++, (argb >> 16) & 255); pixelData.set(i++, (argb >> 8) & 255); pixelData.set(i++, (argb) & 255); pixelData.set(i++, (argb >> 24) & 255); } dst += scanSize; } ctx.putImageData(imageData, startX, startY); }
/** * Returns the alpha value at position (x,y). * * @param x the x coordinate * @param y the y coordinate * @return the alpha value at position (x,y), or 0 if not in the image * @see #setAlphaAt(int, int, int) * @see #getColorAt(int, int, int) */ public final int getAlphaAt(int x, int y) { return getColorAt(x, y, OFFSET_ALPHA); }
/** * Sets the green value at position (x,y). * * @param green the green value * @param x the x coordinate * @param y the y coordinate * @see #getGreenAt(int, int) * @see #getColorAt(int, int, int) */ public final void setGreenAt(int green, int x, int y) { setColorAt(green, x, y, OFFSET_GREEN); }
@Override public void setRgb(int startX, int startY, int width, int height, int[] rgbArray, int offset, int scanSize) { Context2d ctx = canvas.getContext2d(); ImageData imageData = ctx.createImageData(width, height); CanvasPixelArray pixelData = imageData.getData(); int i = 0; int dst = offset; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x ++) { int argb = rgbArray[dst + x]; pixelData.set(i++, (argb >> 16) & 255); pixelData.set(i++, (argb >> 8) & 255); pixelData.set(i++, (argb) & 255); pixelData.set(i++, (argb >> 24) & 255); } dst += scanSize; } ctx.putImageData(imageData, startX, startY); }
/** * Returns the blue value at position (x,y). * * @param x the x coordinate * @param y the y coordinate * @return the blue value at position (x,y), or 0 if not in the image * @see #setBlueAt(int, int, int) * @see #getColorAt(int, int, int) */ public final int getBlueAt(int x, int y) { return getColorAt(x, y, OFFSET_BLUE); }
/** * Sets the red value at position (x,y). * * @param red the red value * @param x the x coordinate * @param y the y coordinate * @see #getRedAt(int, int) * @see #getColorAt(int, int, int) */ public final void setRedAt(int red, int x, int y) { setColorAt(red, x, y, OFFSET_RED); }
@Override public void setRgb(int startX, int startY, int width, int height, int[] rgbArray, int offset, int scanSize) { Context2d ctx = canvas.canvas().getContext2d(); ImageData imageData = ctx.createImageData(width, height); CanvasPixelArray pixelData = imageData.getData(); int i = 0; int dst = offset; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x ++) { int argb = rgbArray[dst + x]; pixelData.set(i++, (argb >> 16) & 255); pixelData.set(i++, (argb >> 8) & 255); pixelData.set(i++, (argb) & 255); pixelData.set(i++, (argb >> 24) & 255); } dst += scanSize; } ctx.putImageData(imageData, startX, startY); } }
/** * Returns the green value at position (x,y). * * @param x the x coordinate * @param y the y coordinate * @return the green value at position (x,y), or 0 if not in the image * @see #setGreenAt(int, int, int) * @see #getColorAt(int, int, int) */ public final int getGreenAt(int x, int y) { return getColorAt(x, y, OFFSET_GREEN); }
/** * Sets the alpha value at position (x,y). * * @param alpha the alpha value * @param x the x coordinate * @param y the y coordinate * @see #getAlphaAt(int, int) * @see #getColorAt(int, int, int) */ public final void setAlphaAt(int alpha, int x, int y) { setColorAt(alpha, x, y, OFFSET_ALPHA); }
height); CanvasPixelArray canvasPixelArray = imageData.getData();
/** * Returns the blue value at position (x,y). * * @param x the x coordinate * @param y the y coordinate * @return the blue value at position (x,y), or 0 if not in the image * @see #setBlueAt(int, int, int) * @see #getColorAt(int, int, int) */ public final int getBlueAt(int x, int y) { return getColorAt(x, y, OFFSET_BLUE); }
/** * Sets the blue value at position (x,y). * * @param blue the blue value * @param x the x coordinate * @param y the y coordinate * @see #getBlueAt(int, int) * @see #getColorAt(int, int, int) */ public final void setBlueAt(int blue, int x, int y) { setColorAt(blue, x, y, OFFSET_BLUE); }
height); CanvasPixelArray canvasPixelArray = imageData.getData();
/** * Returns the green value at position (x,y). * * @param x the x coordinate * @param y the y coordinate * @return the green value at position (x,y), or 0 if not in the image * @see #setGreenAt(int, int, int) * @see #getColorAt(int, int, int) */ public final int getGreenAt(int x, int y) { return getColorAt(x, y, OFFSET_GREEN); }
/** * Sets the alpha value at position (x,y). * * @param alpha the alpha value * @param x the x coordinate * @param y the y coordinate * @see #getAlphaAt(int, int) * @see #getColorAt(int, int, int) */ public final void setAlphaAt(int alpha, int x, int y) { setColorAt(alpha, x, y, OFFSET_ALPHA); }