@Override public Image snapshot() { Bitmap bitmap = ((AndroidImage)this.image).bitmap(); return new AndroidImage(gfx, image.scale(), bitmap.copy(bitmap.getConfig(), false), "<canvas>"); }
/** * This image's height in display units. If this image is loaded asynchrously, this will return * 0 until loading is complete. See {@link #state}. */ public float height () { return scale().invScaled(pixelHeight()); }
/** * This image's width in display units. If this image is loaded asynchrously, this will return * 0 until loading is complete. See {@link #state}. */ public float width () { return scale().invScaled(pixelWidth()); }
/** * This image's width in display units. If this image is loaded asynchrously, this will return * 0 until loading is complete. See {@link #state}. */ public float width () { return scale().invScaled(pixelWidth()); }
/** * This image's height in display units. If this image is loaded asynchrously, this will return * 0 until loading is complete. See {@link #state}. */ public float height () { return scale().invScaled(pixelHeight()); }
@Override public Image snapshot() { return new RoboImage(gfx, image.scale(), ((RoboImage)image).cgImage(), "<canvas>"); }
@Override public Image snapshot() { BufferedImage bmp = ((JavaImage)image).bufferedImage(); ColorModel cm = bmp.getColorModel(); boolean isAlphaPremultiplied = bmp.isAlphaPremultiplied(); WritableRaster raster = bmp.copyData(null); BufferedImage snap = new BufferedImage(cm, raster, isAlphaPremultiplied, null); return new JavaImage(gfx, image.scale(), snap, "<canvas>"); }
@Override public Image snapshot() { BufferedImage bmp = ((JavaImage)image).bufferedImage(); ColorModel cm = bmp.getColorModel(); boolean isAlphaPremultiplied = bmp.isAlphaPremultiplied(); WritableRaster raster = bmp.copyData(null); BufferedImage snap = new BufferedImage(cm, raster, isAlphaPremultiplied, null); return new JavaImage(gfx, image.scale(), snap, "<canvas>"); }
/** * Creates a texture with this image's bitmap data using {@code config}. NOTE: this creates a new * texture with every call. This is generally only needed if you plan to create multiple textures * from the same bitmap, with different configurations. Otherwise just use {@link #texture} to * create the image's "default" texture which will be shared by all callers. */ public Texture createTexture (Texture.Config config) { if (!isLoaded()) throw new IllegalStateException( "Cannot create texture from unready image: " + this); int texWidth = config.toTexWidth(pixelWidth()); int texHeight = config.toTexHeight(pixelHeight()); if (texWidth <= 0 || texHeight <= 0) throw new IllegalArgumentException( "Invalid texture size: " + texWidth + "x" + texHeight + " from: " + this); Texture tex = new Texture(gfx, gfx.createTexture(config), config, texWidth, texHeight, scale(), width(), height()); tex.update(this); // this will handle non-POT source image conversion return tex; }
/** * Creates a texture with this image's bitmap data using {@code config}. NOTE: this creates a new * texture with every call. This is generally only needed if you plan to create multiple textures * from the same bitmap, with different configurations. Otherwise just use {@link #texture} to * create the image's "default" texture which will be shared by all callers. */ public Texture createTexture (Texture.Config config) { if (!isLoaded()) throw new IllegalStateException( "Cannot create texture from unready image: " + this); int texWidth = config.toTexWidth(pixelWidth()); int texHeight = config.toTexHeight(pixelHeight()); if (texWidth <= 0 || texHeight <= 0) throw new IllegalArgumentException( "Invalid texture size: " + texWidth + "x" + texHeight + " from: " + this); Texture tex = new Texture(gfx, gfx.createTexture(config), config, texWidth, texHeight, scale(), width(), height()); tex.update(this); // this will handle non-POT source image conversion return tex; }
@Override public Canvas fillText(TextLayout layout, float x, float y) { RoboGradient gradient = currentState().gradient; RoboTextLayout ilayout = (RoboTextLayout) layout; if (gradient == null) { ilayout.fill(bctx, x, y, fillColor); } else { // draw our text into a fresh context so we can use it as a mask for the gradient CGBitmapContext maskContext = RoboGraphics.createCGBitmap(texWidth(), texHeight()); maskContext.clearRect(new CGRect(0, 0, texWidth(), texHeight())); // scale the context based on our scale factor float scale = image.scale().factor; maskContext.scaleCTM(scale, scale); // fill the text into this temp context in white for use as a mask setFillColor(maskContext, 0xFFFFFFFF); ilayout.fill(maskContext, 0, 0, fillColor); // now fill the gradient, using our temp context as a mask bctx.saveGState(); bctx.clipToMask(new CGRect(x, y, width, height), maskContext.toImage()); gradient.fill(bctx); bctx.restoreGState(); // finally free the temp context maskContext.dispose(); } isDirty = true; return this; }