Class ImageProvider
How to use:
ImageIcon icon = new ImageProvider(name).setMaxSize(ImageSizes.MAP).get();
(there are more options, see below)
short form:
ImageIcon icon = ImageProvider.get(name);
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static enumstatic enumSupported image sizesstatic enumSupported image types -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Filearchive file to take image fromprivate static final Map<String,ImageResource> The icon cacheprivate static final Pointprotected static final intThe cursor hotspot constantsDEFAULT_HOTSPOTandCROSSHAIR_HOTSPOTare relative to this cursor sizeprivate static final Patterndata:[<mediatype>][;base64],<data>private static final Pointprotected Collection<String>directories in which images are searchedprivate static final Stringprivate static final Stringprotected Stringcaching identifierprivate static final ExecutorServiceprotected Stringdirectory inside the archiveprotected booleantrueif icon must be grayed outprotected booleantrueif multi-resolution image is requestedprotected final Stringimage file nameprotected booleanIn case of errors do not throw exception but returnnullfor missing imageprivate static final Map<OsmPrimitiveType,ImageIcon> small cache of critical images used in many parts of the applicationprotected List<ImageOverlay>ordered list of overlay imagesstatic final StringProperty set onBufferedImagereturned byread(java.io.File, boolean, boolean)if metadata is required.static final StringProperty set onBufferedImagereturned bymakeImageTransparent(java.awt.image.BufferedImage, java.awt.Color).protected Stringsub directory the image can be found inprotected booleantrueif warnings should be suppressedprivate static final com.github.weisj.jsvg.parser.SVGLoaderprotected intvirtual height of the resulting image, -1 when original image data should be usedprotected intvirtual maximum height of the resulting image, -1 for no restrictionprotected intvirtual maximum width of the resulting image, -1 for no restrictionprotected intvirtual width of the resulting image, -1 when original image data should be usedprivate static final String -
Constructor Summary
ConstructorsConstructorDescriptionImageProvider(String name) Constructs a newImageProviderfrom a filename.ImageProvider(String subdir, String name) Constructs a newImageProviderfrom a filename in a given directory.ImageProvider(ImageProvider image) Constructs a newImageProviderfrom an existing one. -
Method Summary
Modifier and TypeMethodDescriptionaddOverlay(ImageOverlay overlay) Add an overlay over the image.static voidClears the internal image caches.static ImageIconCreates a blank icon of the given size.static ImagecreateBoundedImage(Image img, int maxSize) Creates a scaled down version of the input image to fit maximum dimensions.(package private) static BufferedImagecreateImageFromSvg(com.github.weisj.jsvg.SVGDocument svg, Dimension dim, ImageResizeMode resizeMode) Constructs an image from the given SVG data.private static ImageInputStreamcreateImageInputStream(Object input) static BufferedImagecreateScaledImage(BufferedImage img, int targetWidth, int targetHeight, Object hint) Returns a scaled instance of the providedBufferedImage.get()Execute the image request and scale result.static ImageIconLoad an image with a given file name.static ImageIconLoad an image with a given file name.static ImageIconget(String subdir, String name, ImageProvider.ImageSizes size) Load an image from directory with a given file name and size.static ImageIconget(String name, ImageProvider.ImageSizes size) Load an image with a given file name and size.static ImageIconget(OsmPrimitiveType type) Replies the icon for an OSM primitive typeLoad the image in a background thread.static CursorLoad a cursor with a given file name, optionally decorated with an overlay image.(package private) static ImagegetCursorImage(String name, String overlay, UnaryOperator<Dimension> bestCursorSizeFunction, Point hotSpot) Load a cursor image with a given file name, optionally decorated with an overlay imageExecute the image request and scale result.static ImageIconLoad an empty image with a given size.static ImageIcongetIfAvailable(String name) Load an image with a given file name, but do not throw an exception when the image cannot be found.static ImageIcongetIfAvailable(String subdir, String name) Load an image with a given file name, but do not throw an exception when the image cannot be found.private static ImageResourceInternal implementation of the image request for inline images (data: urls).private static ImageResourcegetIfAvailableHttp(String url, ImageProvider.ImageType type) Internal implementation of the image request for URL's.private ImageResourceInternal implementation of the image request.private static ImageResourcegetIfAvailableLocalURL(URL path, ImageProvider.ImageType type) Internal implementation of the image request for local images.private static ImageResourcegetIfAvailableWiki(String name, ImageProvider.ImageType type) Internal implementation of the image request for wiki images.private static ImageResourcegetIfAvailableZip(String fullName, File archive, String inArchiveDir, ImageProvider.ImageType type) Internal implementation of the image request for images in Zip archives.static ExecutorReturns the executor used for background image fetching.private URLgetImageUrl(String imageName) private static URLgetImageUrl(String path, String name) private static StringgetImgUrlFromWikiInfoPage(String base, String fn) Reads the wiki page on a certain file in html format in order to find the real image URL.static ImageIcongetPadded(OsmPrimitive primitive, Dimension iconSize) Returns anImageIconfor the given OSM object, at the specified size.Execute the image request.getResourceAsync(Consumer<? super ImageResource> action) Load the image in a background thread.private static com.github.weisj.jsvg.parser.LoaderContextstatic ColorgetTransparentColor(ColorModel model, ImageReader reader) Returns theTransparentColordefined in image reader metadata.static booleanDetermines if the givenBufferedImagehas a transparent color determined by a previous call toread(java.io.File, boolean, boolean).booleanisRemote()Determines if this icon is located on a remote location (http, https, wiki).static booleanDetermines if the transparency of the givenBufferedImagehas been enforced by a previous call tomakeImageTransparent(java.awt.image.BufferedImage, java.awt.Color).static BufferedImagemakeImageTransparent(BufferedImage bi, Color color) Returns a transparent version of the given image, based on the given transparent color.private static Colorstatic BufferedImageReturns aBufferedImageas the result of decoding a suppliedFilewith anImageReaderchosen automatically from among those currently registered.static BufferedImageread(InputStream input, boolean readMetadata, boolean enforceTransparency) Returns aBufferedImageas the result of decoding a suppliedInputStreamwith anImageReaderchosen automatically from among those currently registered.static BufferedImageReturns aBufferedImageas the result of decoding a suppliedURLwith anImageReaderchosen automatically from among those currently registered.static BufferedImageread(URL input, boolean readMetadata, boolean enforceTransparency, Function<ImageReader, ImageReadParam> readParamFunction) Returns aBufferedImageas the result of decoding a suppliedURLwith anImageReaderchosen automatically from among those currently registered.static BufferedImageread(ImageInputStream stream, boolean readMetadata, boolean enforceTransparency) Returns aBufferedImageas the result of decoding a suppliedImageInputStreamwith anImageReaderchosen automatically from among those currently registered.private static BufferedImageread(ImageInputStream stream, boolean readMetadata, boolean enforceTransparency, Function<ImageReader, ImageReadParam> readParamFunction) resetMaxSize(Dimension maxSize) Limit the maximum size of the image.setArchive(File archive) Specify a zip file where the image is located.setDirs(Collection<String> dirs) Directories to look for the image.setDisabled(boolean disabled) Set, if image must be filtered to grayscale so it will look like disabled icon.setHeight(int height) Set image heightSet an id used for caching.setInArchiveDir(String inArchiveDir) Specify a base path inside the zip file.setMaxHeight(int maxHeight) Limit the maximum height of the image.setMaxSize(int maxSize) Convenience method, seesetMaxSize(Dimension).setMaxSize(Dimension maxSize) Limit the maximum size of the image.Limit the maximum size of the image.setMaxWidth(int maxWidth) Limit the maximum width of the image.setMultiResolution(boolean multiResolution) Decide, if multi-resolution image is requested (defaulttrue).setOptional(boolean optional) Decide, if an exception should be thrown, when the image cannot be located.setSize(int width, int height) Set the dimensions of the image.Set the dimensions of the image.Set the dimensions of the image.setSuppressWarnings(boolean suppressWarnings) Suppresses warning on the command line in case the image cannot be found.setWidth(int width) Set image widthstatic voidshutdown(boolean now) Shutdown background image fetcher.static BufferedImagetoBufferedImage(Image image) Converts anImageto aBufferedImageinstance.static BufferedImagetoBufferedImage(Image image, Rectangle cropArea) toString()
-
Field Details
-
HTTP_PROTOCOL
- See Also:
-
HTTPS_PROTOCOL
- See Also:
-
WIKI_PROTOCOL
- See Also:
-
svgloader
-
PROP_TRANSPARENCY_FORCED
Property set onBufferedImagereturned bymakeImageTransparent(java.awt.image.BufferedImage, java.awt.Color).- Since:
- 7132
- See Also:
-
PROP_TRANSPARENCY_COLOR
Property set onBufferedImagereturned byread(java.io.File, boolean, boolean)if metadata is required.- Since:
- 7132
- See Also:
-
dirs
directories in which images are searched -
id
caching identifier -
subdir
sub directory the image can be found in -
name
image file name -
archive
archive file to take image from -
inArchiveDir
directory inside the archive -
virtualWidth
virtual width of the resulting image, -1 when original image data should be used -
virtualHeight
virtual height of the resulting image, -1 when original image data should be used -
virtualMaxWidth
virtual maximum width of the resulting image, -1 for no restriction -
virtualMaxHeight
virtual maximum height of the resulting image, -1 for no restriction -
optional
In case of errors do not throw exception but returnnullfor missing image -
suppressWarnings
trueif warnings should be suppressed -
overlayInfo
ordered list of overlay images -
isDisabled
trueif icon must be grayed out -
multiResolution
trueif multi-resolution image is requested -
cache
The icon cache -
osmPrimitiveTypeCache
small cache of critical images used in many parts of the application -
IMAGE_FETCHER
-
dataUrlPattern
data:[<mediatype>][;base64],<data>- See Also:
-
CURSOR_SIZE_HOTSPOT_IS_RELATIVE_TO
The cursor hotspot constantsDEFAULT_HOTSPOTandCROSSHAIR_HOTSPOTare relative to this cursor size- See Also:
-
DEFAULT_HOTSPOT
-
CROSSHAIR_HOTSPOT
-
-
Constructor Details
-
ImageProvider
Constructs a newImageProviderfrom a filename in a given directory.- Parameters:
subdir- subdirectory the image lies inname- the name of the image. If it does not end with '.png' or '.svg', both extensions are tried.- Throws:
NullPointerException- if name is null
-
ImageProvider
Constructs a newImageProviderfrom a filename.- Parameters:
name- the name of the image. If it does not end with '.png' or '.svg', both extensions are tried.- Throws:
NullPointerException- if name is null
-
ImageProvider
Constructs a newImageProviderfrom an existing one.- Parameters:
image- the existing image provider to be copied- Since:
- 8095
-
-
Method Details
-
setDirs
Directories to look for the image.- Parameters:
dirs- The directories to look for.- Returns:
- the current object, for convenience
-
setId
Set an id used for caching. If name starts withhttp://Id is not used for the cache. (A URL is unique anyway.)- Parameters:
id- the id for the cached image- Returns:
- the current object, for convenience
-
setArchive
Specify a zip file where the image is located.(optional)
- Parameters:
archive- zip file where the image is located- Returns:
- the current object, for convenience
-
setInArchiveDir
Specify a base path inside the zip file.The subdir and name will be relative to this path.
(optional)
- Parameters:
inArchiveDir- path inside the archive- Returns:
- the current object, for convenience
-
addOverlay
Add an overlay over the image. Multiple overlays are possible.- Parameters:
overlay- overlay image and placement specification- Returns:
- the current object, for convenience
- Since:
- 8095
-
setSize
Set the dimensions of the image.If not specified, the original size of the image is used. The width part of the dimension can be -1. Then it will only set the height but keep the aspect ratio. (And the other way around.)
- Parameters:
size- final dimensions of the image- Returns:
- the current object, for convenience
-
setSize
Set the dimensions of the image.If not specified, the original size of the image is used.
- Parameters:
size- final dimensions of the image- Returns:
- the current object, for convenience
- Since:
- 7687
-
setSize
Set the dimensions of the image.- Parameters:
width- final width of the imageheight- final height of the image- Returns:
- the current object, for convenience
- Since:
- 10358
-
setWidth
Set image width- Parameters:
width- final width of the image- Returns:
- the current object, for convenience
- See Also:
-
setHeight
Set image height- Parameters:
height- final height of the image- Returns:
- the current object, for convenience
- See Also:
-
setMaxSize
Limit the maximum size of the image.It will shrink the image if necessary, but keep the aspect ratio. The given width or height can be -1 which means this direction is not bounded.
'size' and 'maxSize' are not compatible, you should set only one of them.
- Parameters:
maxSize- maximum image size- Returns:
- the current object, for convenience
-
resetMaxSize
Limit the maximum size of the image.It will shrink the image if necessary, but keep the aspect ratio. The given width or height can be -1 which means this direction is not bounded.
This function sets value using the most restrictive of the new or existing set of values.
- Parameters:
maxSize- maximum image size- Returns:
- the current object, for convenience
- See Also:
-
setMaxSize
Limit the maximum size of the image.It will shrink the image if necessary, but keep the aspect ratio. The given width or height can be -1 which means this direction is not bounded.
'size' and 'maxSize' are not compatible, you should set only one of them.
- Parameters:
size- maximum image size- Returns:
- the current object, for convenience
- Since:
- 7687
-
setMaxSize
Convenience method, seesetMaxSize(Dimension).- Parameters:
maxSize- maximum image size- Returns:
- the current object, for convenience
-
setMaxWidth
Limit the maximum width of the image.- Parameters:
maxWidth- maximum image width- Returns:
- the current object, for convenience
- See Also:
-
setMaxHeight
Limit the maximum height of the image.- Parameters:
maxHeight- maximum image height- Returns:
- the current object, for convenience
- See Also:
-
setOptional
Decide, if an exception should be thrown, when the image cannot be located.Set to true, when the image URL comes from user data and the image may be missing.
- Parameters:
optional- true, if JOSM should not throw a RuntimeException in case the image cannot be located.- Returns:
- the current object, for convenience
-
setSuppressWarnings
Suppresses warning on the command line in case the image cannot be found.In combination with setOptional(true);
- Parameters:
suppressWarnings- iftruewarnings are suppressed- Returns:
- the current object, for convenience
-
setDisabled
Set, if image must be filtered to grayscale so it will look like disabled icon.- Parameters:
disabled- true, if image must be grayed out for disabled state- Returns:
- the current object, for convenience
- Since:
- 10428
-
setMultiResolution
Decide, if multi-resolution image is requested (defaulttrue).A
java.awt.image.MultiResolutionImageis a Java 9Imageimplementation, which adds support for HiDPI displays. The effect will be that in HiDPI mode, when GUI elements are scaled by a factor 1.5, 2.0, etc., the images are not just up-scaled, but a higher resolution version of the image is rendered instead.Use
HiDPISupport.getBaseImage(java.awt.Image)to extract the original image from a multi-resolution image.See
HiDPISupport.processMRImage(java.awt.Image, java.util.function.UnaryOperator<java.awt.Image>)for how to process the image without removing the multi-resolution magic.- Parameters:
multiResolution- true, if multi-resolution image is requested- Returns:
- the current object, for convenience
-
isRemote
Determines if this icon is located on a remote location (http, https, wiki).- Returns:
trueif this icon is located on a remote location (http, https, wiki)- Since:
- 13250
-
get
Execute the image request and scale result.- Returns:
- the requested image or null if the request failed
-
getDataURL
Execute the image request and scale result.- Returns:
- the requested image as data: URL or null if the request failed
- Since:
- 16872
-
getAsync
Load the image in a background thread.This method returns immediately and runs the image request asynchronously.
- Parameters:
action- the action that will deal with the image- Returns:
- the future of the requested image
- Since:
- 13252
-
getResource
Execute the image request.- Returns:
- the requested image or null if the request failed
- Since:
- 7693
-
getResourceAsync
Load the image in a background thread.This method returns immediately and runs the image request asynchronously for remote resources. For local resources, the request is executed synchronously in the current thread.
- Parameters:
action- the action that will deal with the image- Returns:
- the future of the requested image
- Since:
- 13252
-
getImageFetchExecutor
Returns the executor used for background image fetching. Callers that need to force asynchronous loading even for local resources (e.g. to off-load expensive SVG pre-rendering) may use this executor directly.- Returns:
- the image fetch executor
- Since:
- 19553
-
get
Load an image with a given file name.- Parameters:
subdir- subdirectory the image lies inname- The icon name (base name with or without '.png' or '.svg' extension)- Returns:
- The requested Image.
- Throws:
RuntimeException- if the image cannot be located
-
get
Load an image with a given file name.- Parameters:
name- The icon name (base name with or without '.png' or '.svg' extension)- Returns:
- the requested image or null if the request failed
- See Also:
-
get
Load an image from directory with a given file name and size.- Parameters:
subdir- subdirectory the image lies inname- The icon name (base name with or without '.png' or '.svg' extension)size- Target icon size- Returns:
- The requested Image.
- Throws:
RuntimeException- if the image cannot be located- Since:
- 10428
-
getEmpty
Load an empty image with a given size.- Parameters:
size- Target icon size- Returns:
- The requested Image.
- Since:
- 10358
-
getIfAvailable
Load an image with a given file name, but do not throw an exception when the image cannot be found.- Parameters:
subdir- subdirectory the image lies inname- The icon name (base name with or without '.png' or '.svg' extension)- Returns:
- the requested image or null if the request failed
- See Also:
-
get
Load an image with a given file name and size.- Parameters:
name- The icon name (base name with or without '.png' or '.svg' extension)size- Target icon size- Returns:
- the requested image or null if the request failed
- Since:
- 10428
- See Also:
-
getIfAvailable
Load an image with a given file name, but do not throw an exception when the image cannot be found.- Parameters:
name- The icon name (base name with or without '.png' or '.svg' extension)- Returns:
- the requested image or null if the request failed
- See Also:
-
clearCache
Clears the internal image caches.- Since:
- 11021
-
getIfAvailableImpl
Internal implementation of the image request.- Returns:
- the requested image or null if the request failed
-
getIfAvailableHttp
Internal implementation of the image request for URL's.- Parameters:
url- URL of the imagetype- data type of the image- Returns:
- the requested image or null if the request failed
-
getIfAvailableDataUrl
Internal implementation of the image request for inline images (data: urls).- Parameters:
url- the data URL for image extraction- Returns:
- the requested image or null if the request failed
-
getIfAvailableWiki
Internal implementation of the image request for wiki images.- Parameters:
name- image file nametype- data type of the image- Returns:
- the requested image or null if the request failed
-
getIfAvailableZip
private static ImageResource getIfAvailableZip(String fullName, File archive, String inArchiveDir, ImageProvider.ImageType type) Internal implementation of the image request for images in Zip archives.- Parameters:
fullName- image file namearchive- the archive to get image frominArchiveDir- directory of the image inside the archive ornulltype- data type of the image- Returns:
- the requested image or null if the request failed
-
getIfAvailableLocalURL
Internal implementation of the image request for local images.- Parameters:
path- image file pathtype- data type of the image- Returns:
- the requested image or null if the request failed
-
getImageUrl
-
getImageUrl
-
getImgUrlFromWikiInfoPage
Reads the wiki page on a certain file in html format in order to find the real image URL.- Parameters:
base- base URL for Wiki imagefn- filename of the Wiki image- Returns:
- image URL for a Wiki image or null in case of error
-
getCursor
Load a cursor with a given file name, optionally decorated with an overlay image.- Parameters:
name- the cursor image filename in "cursor" directoryoverlay- optional overlay image- Returns:
- cursor with a given file name, optionally decorated with an overlay image
-
getCursorImage
static Image getCursorImage(String name, String overlay, UnaryOperator<Dimension> bestCursorSizeFunction, Point hotSpot) Load a cursor image with a given file name, optionally decorated with an overlay image- Parameters:
name- the cursor image filename in "cursor" directoryoverlay- optional overlay imagebestCursorSizeFunction- computes the best cursor size, seeToolkit.getBestCursorSize(int, int)hotSpot- will be set to the properly scaled hotspot of the cursor- Returns:
- cursor with a given file name, optionally decorated with an overlay image
-
createBoundedImage
Creates a scaled down version of the input image to fit maximum dimensions. (Keeps aspect ratio)- Parameters:
img- the image to be scaled down.maxSize- the maximum size in pixels (both for width and height)- Returns:
- the image after scaling.
- Since:
- 6172
-
createScaledImage
public static BufferedImage createScaledImage(BufferedImage img, int targetWidth, int targetHeight, Object hint) Returns a scaled instance of the providedBufferedImage. This method will use a multi-step scaling technique that provides higher quality than the usual one-step technique (only useful in downscaling cases, wheretargetWidthortargetHeightis smaller than the original dimensions, and generally only when theBILINEARhint is specified).- Parameters:
img- the original image to be scaledtargetWidth- the desired width of the scaled instance, in pixelstargetHeight- the desired height of the scaled instance, in pixelshint- one of the rendering hints that corresponds toRenderingHints.KEY_INTERPOLATION(e.g.RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR,RenderingHints.VALUE_INTERPOLATION_BILINEAR,RenderingHints.VALUE_INTERPOLATION_BICUBIC)- Returns:
- a scaled version of the original
BufferedImage - Since:
- 13038
-
get
Replies the icon for an OSM primitive type- Parameters:
type- the type- Returns:
- the icon
-
getPadded
Returns anImageIconfor the given OSM object, at the specified size. This is a slow operation.- Parameters:
primitive- Object for which an icon shall be fetched. The icon is chosen based on tags.iconSize- Target size of icon. Icon is padded if required.- Returns:
- Icon for
primitivethat fits in cell. - Since:
- 8903
-
createImageFromSvg
static BufferedImage createImageFromSvg(com.github.weisj.jsvg.SVGDocument svg, Dimension dim, ImageResizeMode resizeMode) Constructs an image from the given SVG data.- Parameters:
svg- the SVG datadim- the desired image dimensionresizeMode- how to size/resize the image- Returns:
- an image from the given SVG data at the desired dimension.
-
read
public static BufferedImage read(File input, boolean readMetadata, boolean enforceTransparency) throws IOException Returns aBufferedImageas the result of decoding a suppliedFilewith anImageReaderchosen automatically from among those currently registered. TheFileis wrapped in anImageInputStream. If no registeredImageReaderclaims to be able to read the resulting stream,nullis returned.The current cache settings from
getUseCacheandgetCacheDirectorywill be used to control caching in theImageInputStreamthat is created.Note that there is no
readmethod that takes a filename as aString; use this method instead after creating aFilefrom the filename.This method does not attempt to locate
ImageReaders that can read directly from aFile; that may be accomplished usingIIORegistryandImageReaderSpi.- Parameters:
input- aFileto read from.readMetadata- iftrue, makes sure to read image metadata to detect transparency color, if any. In that case the color can be retrieved later throughPROP_TRANSPARENCY_COLOR. Always consideredtrueifenforceTransparencyis alsotrueenforceTransparency- iftrue, makes sure to read image metadata and, if the image does not provide an alpha channel but defines aTransparentColormetadata node, that the resulting image has a transparency set toTRANSLUCENTand uses the correct transparent color.- Returns:
- a
BufferedImagecontaining the decoded contents of the input, ornull. - Throws:
IllegalArgumentException- ifinputisnull.IOException- if an error occurs during reading.- Since:
- 7132
- See Also:
-
read
public static BufferedImage read(InputStream input, boolean readMetadata, boolean enforceTransparency) throws IOException Returns aBufferedImageas the result of decoding a suppliedInputStreamwith anImageReaderchosen automatically from among those currently registered. TheInputStreamis wrapped in anImageInputStream. If no registeredImageReaderclaims to be able to read the resulting stream,nullis returned.The current cache settings from
getUseCacheandgetCacheDirectorywill be used to control caching in theImageInputStreamthat is created.This method does not attempt to locate
ImageReaders that can read directly from anInputStream; that may be accomplished usingIIORegistryandImageReaderSpi.This method does not close the provided
InputStreamafter the read operation has completed; it is the responsibility of the caller to close the stream, if desired.- Parameters:
input- anInputStreamto read from.readMetadata- iftrue, makes sure to read image metadata to detect transparency color for non translucent images, if any. In that case the color can be retrieved later throughPROP_TRANSPARENCY_COLOR. Always consideredtrueifenforceTransparencyis alsotrueenforceTransparency- iftrue, makes sure to read image metadata and, if the image does not provide an alpha channel but defines aTransparentColormetadata node, that the resulting image has a transparency set toTRANSLUCENTand uses the correct transparent color.- Returns:
- a
BufferedImagecontaining the decoded contents of the input, ornull. - Throws:
IllegalArgumentException- ifinputisnull.IOException- if an error occurs during reading.- Since:
- 7132
-
read
public static BufferedImage read(URL input, boolean readMetadata, boolean enforceTransparency) throws IOException Returns aBufferedImageas the result of decoding a suppliedURLwith anImageReaderchosen automatically from among those currently registered. AnInputStreamis obtained from theURL, which is wrapped in anImageInputStream. If no registeredImageReaderclaims to be able to read the resulting stream,nullis returned.The current cache settings from
getUseCacheandgetCacheDirectorywill be used to control caching in theImageInputStreamthat is created.This method does not attempt to locate
ImageReaders that can read directly from aURL; that may be accomplished usingIIORegistryandImageReaderSpi.- Parameters:
input- aURLto read from.readMetadata- iftrue, makes sure to read image metadata to detect transparency color for non translucent images, if any. In that case the color can be retrieved later throughPROP_TRANSPARENCY_COLOR. Always consideredtrueifenforceTransparencyis alsotrueenforceTransparency- iftrue, makes sure to read image metadata and, if the image does not provide an alpha channel but defines aTransparentColormetadata node, that the resulting image has a transparency set toTRANSLUCENTand uses the correct transparent color.- Returns:
- a
BufferedImagecontaining the decoded contents of the input, ornull. - Throws:
IllegalArgumentException- ifinputisnull.IOException- if an error occurs during reading.- Since:
- 7132
-
read
public static BufferedImage read(URL input, boolean readMetadata, boolean enforceTransparency, Function<ImageReader, ImageReadParam> readParamFunction) throws IOExceptionReturns aBufferedImageas the result of decoding a suppliedURLwith anImageReaderchosen automatically from among those currently registered. AnInputStreamis obtained from theURL, which is wrapped in anImageInputStream. If no registeredImageReaderclaims to be able to read the resulting stream,nullis returned.The current cache settings from
getUseCacheandgetCacheDirectorywill be used to control caching in theImageInputStreamthat is created.This method does not attempt to locate
ImageReaders that can read directly from aURL; that may be accomplished usingIIORegistryandImageReaderSpi.- Parameters:
input- aURLto read from.readMetadata- iftrue, makes sure to read image metadata to detect transparency color for non translucent images, if any. In that case the color can be retrieved later throughPROP_TRANSPARENCY_COLOR. Always consideredtrueifenforceTransparencyis alsotrueenforceTransparency- iftrue, makes sure to read image metadata and, if the image does not provide an alpha channel but defines aTransparentColormetadata node, that the resulting image has a transparency set toTRANSLUCENTand uses the correct transparent color.readParamFunction- a function to compute the read parameters from the image reader- Returns:
- a
BufferedImagecontaining the decoded contents of the input, ornull. - Throws:
IllegalArgumentException- ifinputisnull.IOException- if an error occurs during reading.- Since:
- 17880
-
read
public static BufferedImage read(ImageInputStream stream, boolean readMetadata, boolean enforceTransparency) throws IOException Returns aBufferedImageas the result of decoding a suppliedImageInputStreamwith anImageReaderchosen automatically from among those currently registered. If no registeredImageReaderclaims to be able to read the stream,nullis returned.Unlike most other methods in this class, this method does close the provided
ImageInputStreamafter the read operation has completed, unlessnullis returned, in which case this method does not close the stream.- Parameters:
stream- anImageInputStreamto read from.readMetadata- iftrue, makes sure to read image metadata to detect transparency color for non translucent images, if any. In that case the color can be retrieved later throughPROP_TRANSPARENCY_COLOR. Always consideredtrueifenforceTransparencyis alsotrueenforceTransparency- iftrue, makes sure to read image metadata and, if the image does not provide an alpha channel but defines aTransparentColormetadata node, that the resulting image has a transparency set toTRANSLUCENTand uses the correct transparent color. For Java < 11 only.- Returns:
- a
BufferedImagecontaining the decoded contents of the input, ornull. - Throws:
IllegalArgumentException- ifstreamisnull.IOException- if an error occurs during reading.- Since:
- 7132
-
read
private static BufferedImage read(ImageInputStream stream, boolean readMetadata, boolean enforceTransparency, Function<ImageReader, ImageReadParam> readParamFunction) throws IOException- Throws:
IOException
-
getTransparentColor
Returns theTransparentColordefined in image reader metadata.- Parameters:
model- The image color modelreader- The image reader- Returns:
- the
TransparentColordefined in image reader metadata, ornull - Throws:
IOException- if an error occurs during reading- Since:
- 7499
- See Also:
-
parseRGB
-
makeImageTransparent
Returns a transparent version of the given image, based on the given transparent color.- Parameters:
bi- The image to convertcolor- The transparent color- Returns:
- The same image as
biwhere all pixels of the given color are transparent. This resulting image has also the special propertyPROP_TRANSPARENCY_FORCEDset tocolor - Since:
- 7132
- See Also:
-
isTransparencyForced
Determines if the transparency of the givenBufferedImagehas been enforced by a previous call tomakeImageTransparent(java.awt.image.BufferedImage, java.awt.Color).- Parameters:
bi- TheBufferedImageto test- Returns:
trueif the transparency ofbihas been enforced by a previous call tomakeImageTransparent.- Since:
- 7132
- See Also:
-
hasTransparentColor
Determines if the givenBufferedImagehas a transparent color determined by a previous call toread(java.io.File, boolean, boolean).- Parameters:
bi- TheBufferedImageto test- Returns:
trueifbihas a transparent color determined by a previous call toread.- Since:
- 7132
- See Also:
-
shutdown
Shutdown background image fetcher.- Parameters:
now- iftrue, attempts to stop all actively executing tasks, halts the processing of waiting tasks. iffalse, initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted- Since:
- 8412
-
toBufferedImage
Converts anImageto aBufferedImageinstance.- Parameters:
image- image to convert- Returns:
- a
BufferedImageinstance for the givenImage. - Since:
- 13038
-
toBufferedImage
- Parameters:
image- image to convertcropArea- rectangle to crop image with- Returns:
- a
BufferedImageinstance for the cropped area ofImage. - Since:
- 13127
-
createImageInputStream
- Throws:
IOException
-
createBlankIcon
Creates a blank icon of the given size.- Parameters:
size- image size- Returns:
- a blank icon of the given size
- Since:
- 13984
-
getSVGContext
-
toString
-