public JavaCanvas (Graphics gfx, JavaImage image) { super(gfx, image); g2d = image.bufferedImage().createGraphics(); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); float scale = image.scale().factor; g2d.scale(scale, scale); // push default state stateStack.push(new JavaCanvasState()); // All clears go to rgba(0,0,0,0). g2d.setBackground(new Color(0, true)); }
public JavaCanvas (Graphics gfx, JavaImage image) { super(gfx, image); g2d = image.bufferedImage().createGraphics(); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); float scale = image.scale().factor; g2d.scale(scale, scale); // push default state stateStack.push(new JavaCanvasState()); // All clears go to rgba(0,0,0,0). g2d.setBackground(new Color(0, true)); }
@Override public void draw (Object ctx, float dx, float dy, float dw, float dh, float sx, float sy, float sw, float sh) { // adjust our source rect to account for the scale factor float f = scale().factor; sx *= f; sy *= f; sw *= f; sh *= f; // now render the image through a clip and with a scaling transform, so that only the desired // source rect is rendered, and is rendered into the desired target region float scaleX = dw/sw, scaleY = dh/sh; Graphics2D gfx = (Graphics2D)ctx; Shape oclip = gfx.getClip(); gfx.clipRect(MathUtil.ifloor(dx), MathUtil.ifloor(dy), MathUtil.iceil(dw), MathUtil.iceil(dh)); gfx.drawImage(img, new AffineTransform(scaleX, 0f, 0f, scaleY, dx-sx*scaleX, dy-sy*scaleY), null); gfx.setClip(oclip); }
@Override public void draw (Object ctx, float dx, float dy, float dw, float dh, float sx, float sy, float sw, float sh) { // adjust our source rect to account for the scale factor float f = scale().factor; sx *= f; sy *= f; sw *= f; sh *= f; // now render the image through a clip and with a scaling transform, so that only the desired // source rect is rendered, and is rendered into the desired target region float scaleX = dw/sw, scaleY = dh/sh; Graphics2D gfx = (Graphics2D)ctx; Shape oclip = gfx.getClip(); gfx.clipRect(MathUtil.ifloor(dx), MathUtil.ifloor(dy), MathUtil.iceil(dw), MathUtil.iceil(dh)); gfx.drawImage(img, new AffineTransform(scaleX, 0f, 0f, scaleY, dx-sx*scaleX, dy-sy*scaleY), null); gfx.setClip(oclip); }