Class Java2DUtils
java.lang.Object
is.galia.processor.Java2DUtils
Collection of methods for operating on BufferedImage
s.
-
Method Summary
Modifier and TypeMethodDescriptionstatic BufferedImage
convertCMYKToRGB
(BufferedImage image) static BufferedImage
convertCMYKToRGB
(Raster cmykRaster, ICC_Profile cmykProfile) static BufferedImage
convertIndexedToARGB
(BufferedImage inImage) static BufferedImage
convertToSRGB
(BufferedImage image, ICC_Profile profile) Converts an image to sRGB color space using its embedded ICC profile.static void
convertYCCKToCMYK
(WritableRaster raster) static BufferedImage
crop
(BufferedImage inImage, Crop crop, ReductionFactor rf, ScaleConstraint scaleConstraint) Crops the given image taking into account a reduction factor.static void
invertColor
(WritableRaster raster) static BufferedImage
newImage
(int width, int height, byte[] samples, ComponentOrder componentOrder) Creates a new image backed by the given samples.static BufferedImage
newTestPatternImage
(int width, int height, int type) Generates a new test pattern image consisting of red, green, blue, and alpha (if supported by the given type) bars of equal width.static BufferedImage
removeAlpha
(BufferedImage inImage, Color bgColor) Creates a new image without alpha, paints the given background color into it, draws the RGB channels of the given image into it, and returns it.static RenderedImage
removeAlpha
(RenderedImage inImage, Color bgColor) Creates a new image without alpha, paints the given background color into it, draws the RGB channels of the given image into it, and returns it.static BufferedImage
scale
(BufferedImage inImage, Scale scale, ScaleConstraint scaleConstraint, ReductionFactor reductionFactor, boolean isLinear) Scales an image, taking an already-applied reduction factor into account.
-
Method Details
-
convertIndexedToARGB
- Parameters:
inImage
- Image to convert.- Returns:
- New image of type
BufferedImage.TYPE_4BYTE_ABGR
, or the input image if it is not indexed.
-
convertCMYKToRGB
- Parameters:
image
- CMYK image.- Returns:
- New RGB instance.
- Throws:
IOException
-
convertCMYKToRGB
public static BufferedImage convertCMYKToRGB(Raster cmykRaster, ICC_Profile cmykProfile) throws IOException - Parameters:
cmykRaster
- CMYK image raster.cmykProfile
- Ifnull
, adefault CMYK profile
will be used.- Throws:
IOException
-
convertYCCKToCMYK
-
convertToSRGB
Converts an image to sRGB color space using its embedded ICC profile.- Parameters:
image
- Image to apply the profile to.profile
- The image's embedded profile.- Returns:
- New image with profile applied.
-
crop
public static BufferedImage crop(BufferedImage inImage, Crop crop, ReductionFactor rf, ScaleConstraint scaleConstraint) Crops the given image taking into account a reduction factor. (In other words, the dimensions of the input image have already been halved
reductionFactor
times but the given region is relative to the full-sized image.This method should only be invoked if
Crop.hasEffect(Size, OperationList)
returnstrue
.- Parameters:
inImage
- Image to crop.crop
- Crop operation. Clients should callOperation.hasEffect(Size, OperationList)
before invoking.rf
- Number of times the dimensions ofinImage
have already been halved relative to the full- sized version.scaleConstraint
- Scale constraint.- Returns:
- Cropped image, or the input image if the given region is a no-op. Note that the image is simply a wrapper around the same data buffer.
-
invertColor
-
newImage
public static BufferedImage newImage(int width, int height, byte[] samples, ComponentOrder componentOrder) Creates a new image backed by the given samples.- Parameters:
width
- Width of the image.height
- Height of the image.samples
- Array of samples (one byte per sample).componentOrder
- Order of the samples in the given array.- Returns:
- New image backed by the given samples with no copying.
-
newTestPatternImage
Generates a new test pattern image consisting of red, green, blue, and alpha (if supported by the given type) bars of equal width.- Parameters:
width
- Width.height
- Height.type
- One of theBufferedImage.getType()
constant values.- Returns:
- New image.
-
removeAlpha
Creates a new image without alpha, paints the given background color into it, draws the RGB channels of the given image into it, and returns it.- Parameters:
inImage
- Image with alpha.- Returns:
- Flattened image, or the input image if it has no alpha.
-
removeAlpha
Creates a new image without alpha, paints the given background color into it, draws the RGB channels of the given image into it, and returns it.- Parameters:
inImage
- Image with alpha.- Returns:
- Flattened image, or the input image if it has no alpha.
-
scale
public static BufferedImage scale(BufferedImage inImage, Scale scale, ScaleConstraint scaleConstraint, ReductionFactor reductionFactor, boolean isLinear) Scales an image, taking an already-applied reduction factor into account. In other words, the dimensions of the input image have already been halved
ReductionFactor.factor
times but the given scale is relative to the full-sized image.If one or both target dimensions would end up being less than three pixels, an empty image (with the correct dimensions) is returned.
- Parameters:
inImage
- Image to scale.scale
- Requested size ignoring any reduction factor. If no resample filter is set, a default will be used.Operation.hasEffect(Size, OperationList)
should be called before invoking.scaleConstraint
- Scale constraint.reductionFactor
- Reduction factor that has already been applied to inImage.isLinear
- Whether the provided image is in a linear color space.- Returns:
- Scaled image, or the input image if the given arguments would result in a no-op.
-