Package dev.avelar.mapnik
Class Image
java.lang.Object
dev.avelar.mapnik.Image
- All Implemented Interfaces:
AutoCloseable
A raster image in 8-bit RGBA, such as a rendered map or a picture loaded from a file. Pixels are
exposed as ARGB ints,
0xAARRGGBB, the same as BufferedImage.TYPE_INT_ARGB,
with straight (not premultiplied) alpha. Holds native memory: close it.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classThe size and format of an encoded image, read without decoding the pixels. -
Method Summary
Modifier and TypeMethodDescriptionapplyOpacity(double opacity) Multiply every pixel's alpha byopacity, from 0 to 1.voidclose()colorToAlpha(Color color) Make pixels of this colour transparent.Drawsourceonto this image with normal blending, its top left corner at (dx, dy).Drawsourceonto this image at (dx, dy) with a blend mode and an opacity from 0 to 1.copy()An independent copy.static Imagecreate(int width, int height) A new fully transparent image.crop(int x, int y, int width, int height) A copy of part of this image.Set every pixel: a colour name,"#rrggbb"or"rgba(r,g,b,a)".Asfilter(String...), with a scale factor for sizes inside the filters, as inRenderOptions.Apply Mapnik image filters in place, in order.static ImagefromBufferedImage(BufferedImage source) A new image with the pixels of anyBufferedImage, converted to straight ARGB.intgetArgb(int x, int y) The pixel at (x, y) as0xAARRGGBB.intheight()booleanisSolid()True if every pixel has the same value.static Imageload(byte[] data) Decode image data held in memory.static ImageLoad a PNG, JPEG, TIFF or WebP file, whichever Mapnik was built to read.static Image.Infoprobe(byte[] data) Read the size and format of encoded image data without decoding it.static Image.InfoRead the size and format of an image file without decoding it.voidsave(Path file, ImageFormat format) voidscaled(int width, int height) A resized copy, using bilinear resampling.scaled(int width, int height, ScalingMethod method) A resized copy.setArgb(int x, int y, int argb) int[]toArgb()All pixels as0xAARRGGBB, row by row from the top left.A copy as aBufferedImageof typeTYPE_INT_ARGB.byte[]toBytes(ImageFormat format) AstoBytes(String), with a format built byImageFormat.byte[]Encode the image.byte[]toPng()warp(String sourceSrs, Box2d sourceExtent, String targetSrs, Box2d targetExtent, int width, int height, ScalingMethod method) Reproject this image, which coverssourceExtentinsourceSrs, into a new image ofwidthxheightpixels that coverstargetExtentintargetSrs.warp(String sourceSrs, Box2d sourceExtent, String targetSrs, Box2d targetExtent, int width, int height, ScalingMethod method, int meshSize) As above, with the size in pixels of the grid the warp is approximated on (Mapnik's default is 16).intwidth()
-
Method Details
-
create
A new fully transparent image. -
load
Load a PNG, JPEG, TIFF or WebP file, whichever Mapnik was built to read. -
load
Decode image data held in memory. -
width
public int width() -
height
public int height() -
getArgb
public int getArgb(int x, int y) The pixel at (x, y) as0xAARRGGBB. ThrowsIndexOutOfBoundsExceptionif outside the image. -
setArgb
-
fill
Set every pixel: a colour name,"#rrggbb"or"rgba(r,g,b,a)". -
fill
-
filter
Apply Mapnik image filters in place, in order. Build them withImageFiltersor write theimage-filterssyntax yourself, for example"agg-stack-blur(5,5) invert". ThrowsMapnikExceptionfor a filter Mapnik cannot parse; the image is then unchanged. -
filter
Asfilter(String...), with a scale factor for sizes inside the filters, as inRenderOptions. -
composite
Drawsourceonto this image with normal blending, its top left corner at (dx, dy). Parts outside are clipped. -
composite
Drawsourceonto this image at (dx, dy) with a blend mode and an opacity from 0 to 1. The source may be any size and is not changed. Parts outside this image are clipped. -
scaled
A resized copy, using bilinear resampling. -
scaled
A resized copy. This image is not changed. Close the result. -
warp
public Image warp(String sourceSrs, Box2d sourceExtent, String targetSrs, Box2d targetExtent, int width, int height, ScalingMethod method) Reproject this image, which coverssourceExtentinsourceSrs, into a new image ofwidthxheightpixels that coverstargetExtentintargetSrs. Areas of the new image that fall outside the source are transparent. Use a small target extent to zoom in, andScalingMethod.BILINEARunless you need hard pixels. Close the result. -
warp
public Image warp(String sourceSrs, Box2d sourceExtent, String targetSrs, Box2d targetExtent, int width, int height, ScalingMethod method, int meshSize) As above, with the size in pixels of the grid the warp is approximated on (Mapnik's default is 16). -
crop
A copy of part of this image. ThrowsMapnikExceptionif the area is not inside the image. -
copy
An independent copy. -
applyOpacity
Multiply every pixel's alpha byopacity, from 0 to 1. -
colorToAlpha
Make pixels of this colour transparent. Pixels that only partly match become partly transparent. -
probe
Read the size and format of an image file without decoding it. -
probe
Read the size and format of encoded image data without decoding it. -
isSolid
public boolean isSolid()True if every pixel has the same value. -
toArgb
public int[] toArgb()All pixels as0xAARRGGBB, row by row from the top left. -
toBufferedImage
A copy as aBufferedImageof typeTYPE_INT_ARGB. Needs thejava.desktopmodule, which every full JDK has; a class that never calls this does not load it. -
fromBufferedImage
A new image with the pixels of anyBufferedImage, converted to straight ARGB. Close it. Sets one pixel at a time, so a very large picture takes a moment. -
toBytes
Encode the image.formatispng,jpeg,webportiff, optionally with options, such aspng8,png256,jpeg90,png:z=9. -
toBytes
AstoBytes(String), with a format built byImageFormat. -
save
-
toPng
public byte[] toPng() -
save
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-