Class BufferedDynamicImageResource
- java.lang.Object
-
- org.apache.wicket.request.resource.AbstractResource
-
- org.apache.wicket.request.resource.DynamicImageResource
-
- org.apache.wicket.markup.html.image.resource.BufferedDynamicImageResource
-
- All Implemented Interfaces:
Serializable
,IResource
,IClusterable
public class BufferedDynamicImageResource extends DynamicImageResource
A DynamicImageResource subclass that holds a BufferedImage generated by code elsewhere. The image is held in a non-transient field, and so if this resource is clustered, the entire image will be serialized and copied. If you can regenerate your image by drawing on a Graphics2D, you should prefer the RenderedDynamicImageResource class instead since its image data is transient and therefore it is very lightweight when clustered.The format of the image (and therefore the resource's extension) can be specified with setFormat(String). The default format is "PNG" because JPEG is lossy and makes generated images look bad and GIF has patent issues.
- Author:
- Jonathan Locke
- See Also:
RenderedDynamicImageResource
, Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.wicket.request.resource.AbstractResource
AbstractResource.ContentRangeType, AbstractResource.ResourceResponse, AbstractResource.WriteCallback
-
Nested classes/interfaces inherited from interface org.apache.wicket.request.resource.IResource
IResource.Attributes
-
-
Field Summary
-
Fields inherited from class org.apache.wicket.request.resource.AbstractResource
CONTENT_DISPOSITION_HEADER_NAME, CONTENT_RANGE_ENDBYTE, CONTENT_RANGE_STARTBYTE, INTERNAL_HEADERS
-
-
Constructor Summary
Constructors Constructor Description BufferedDynamicImageResource()
Construct.BufferedDynamicImageResource(String format)
Construct.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected byte[]
getImageData(IResource.Attributes attributes)
Get image data for our dynamic image resource.void
setImage(BufferedImage image)
-
Methods inherited from class org.apache.wicket.request.resource.DynamicImageResource
configureResponse, getFormat, newResourceResponse, setFormat, setLastModifiedTime, toImageData
-
Methods inherited from class org.apache.wicket.request.resource.AbstractResource
configureCache, getCachingStrategy, respond, setRequestMetaData, setRequestRangeMetaData, setResponseContentRangeHeaderFields, setResponseHeaders
-
-
-
-
Constructor Detail
-
BufferedDynamicImageResource
public BufferedDynamicImageResource()
Construct.
-
BufferedDynamicImageResource
public BufferedDynamicImageResource(String format)
Construct.- Parameters:
format
-
-
-
Method Detail
-
setImage
public void setImage(BufferedImage image)
- Parameters:
image
- The image to set
-
getImageData
protected byte[] getImageData(IResource.Attributes attributes)
Description copied from class:DynamicImageResource
Get image data for our dynamic image resource. If the subclass regenerates the data, it should set theDynamicImageResource.setLastModifiedTime(Instant)
when it does so. This ensures that image caching works correctly.- Specified by:
getImageData
in classDynamicImageResource
- Parameters:
attributes
- the context bringing the request, response and the parameters- Returns:
- The image data for this dynamic image.
null
means there is no image and 404 (Not found) response will be return.
-
-