public class ImageScaler extends Object
isDrawBackground()
is activated the resulting image will have the defined size. Any non
image data will be filled with the color defined by setBackgroundColor(Color)
,
isSameAspectRatio()
must return true in that case. In case the image is smaller than the
target size it won't be upscaled but the remaining data will be filled with the background color
if isDrawBackground()
returns true.Constructor and Description |
---|
ImageScaler(ImageSize size,
ImageFormatType imageFormatType)
Construct a new scaler
|
ImageScaler(int height,
int width,
ImageFormatType imageFormatType)
Construct a new scaler
|
Modifier and Type | Method and Description |
---|---|
ImageFormatType |
getFormatType() |
int |
getHeight() |
int |
getWidth() |
boolean |
isDrawBackground() |
boolean |
isSameAspectRatio() |
byte[] |
resizeImage(byte[] data)
Resizes a byte array of an image and returns the transformed byte array image.
|
void |
setBackgroundColor(Color backgroundColor) |
void |
setDimension(ImageSize size) |
void |
setDrawBackground(boolean drawBackground) |
void |
setFormatType(ImageFormatType formatType) |
void |
setHeight(int height) |
void |
setHorizontalAlignment(int alignment)
Set the alignment to use for positioning the image horizontally within the scaled image.
|
void |
setSameAspectRatio(boolean sameAspectRatio) |
void |
setVerticalAlignment(int alignment)
Set the alignment to use for positioning the image vertically within the scaled image.
|
void |
setWidth(int width) |
public ImageScaler(ImageSize size, ImageFormatType imageFormatType)
size
- the maximum size of the resulting imageimageFormatType
- the image format typepublic ImageScaler(int height, int width, ImageFormatType imageFormatType)
height
- maximal height of the resulting imagewidth
- maximal width of the resulting imageimageFormatType
- the image format of the scaled imagepublic ImageFormatType getFormatType()
public int getHeight()
public int getWidth()
public boolean isDrawBackground()
public boolean isSameAspectRatio()
public byte[] resizeImage(byte[] data)
sameAspectRatio
is true
the resulting image is scaled proportionally to the
specified width or height. Images smaller than the defined dimensions will not be changed.data
- Binary image datapublic void setBackgroundColor(Color backgroundColor)
backgroundColor
- the background color to use when isDrawBackground()
is truepublic void setDimension(ImageSize size)
size
- the maximum size of the resulting imagepublic void setDrawBackground(boolean drawBackground)
drawBackground
- true to draw a background to reach the exact size as defined (only used if
setSameAspectRatio(boolean)
is true)public void setFormatType(ImageFormatType formatType)
formatType
- the ImageFormatType
to usepublic void setHeight(int height)
height
- the maximum height of the imagepublic void setHorizontalAlignment(int alignment)
alignment
- a value describing the horizontal alignment of the imagepublic void setSameAspectRatio(boolean sameAspectRatio)
sameAspectRatio
- Set to true
to preserve the aspect ratio.public void setVerticalAlignment(int alignment)
alignment
- a value describing the vertical alignment of the imagepublic void setWidth(int width)
width
- the maximum width for the resulting imageCopyright © 2019 Communote team. All rights reserved.