Package pl.edu.icm.unity.attr
Class UnityImage
- java.lang.Object
-
- pl.edu.icm.unity.attr.UnityImage
-
public class UnityImage extends Object
Class providing Image related information and operations. Currently supports JPG, GIF and PNG image types.- Author:
- R. Ledzinski
-
-
Constructor Summary
Constructors Constructor Description UnityImage(byte[] rawData, ImageType type)
UnityImage(BufferedImage bufferedImage, ImageType type)
UnityImage(String serializedObject)
UnityImage(Path path)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
deserialize(String stringRepresentation)
BufferedImage
getBufferedImage()
int
getHeight()
byte[]
getImage()
byte[]
getScaledDownImage(int maxWidth, int maxHeight)
Recreate the image to match given maximum width and height keeping current aspect ratio.ImageType
getType()
int
getWidth()
void
scaleDown(int maxWidth, int maxHeight)
Recreate the image to match given maximum width and height keeping current aspect ratio.String
serialize()
void
setImage(byte[] image, ImageType type)
Updates object's fields, if given buffer contains data that may be converted to image.
-
-
-
Constructor Detail
-
UnityImage
public UnityImage(String serializedObject) throws IOException
- Throws:
IOException
-
UnityImage
public UnityImage(byte[] rawData, ImageType type)
-
UnityImage
public UnityImage(BufferedImage bufferedImage, ImageType type)
-
UnityImage
public UnityImage(Path path) throws IOException
- Throws:
IOException
-
-
Method Detail
-
getImage
public byte[] getImage()
-
getScaledDownImage
public byte[] getScaledDownImage(int maxWidth, int maxHeight)
Recreate the image to match given maximum width and height keeping current aspect ratio. If image already fits the size no action in taken. Method returns new byte array - current object is not modified.- Parameters:
maxWidth
-maxHeight
-
-
getBufferedImage
public BufferedImage getBufferedImage()
-
getType
public ImageType getType()
-
getWidth
public int getWidth()
-
getHeight
public int getHeight()
-
setImage
public void setImage(byte[] image, ImageType type)
Updates object's fields, if given buffer contains data that may be converted to image. If not possible to convert object remains unchanged.- Parameters:
image
- Byte array containing image data.
-
scaleDown
public void scaleDown(int maxWidth, int maxHeight)
Recreate the image to match given maximum width and height keeping current aspect ratio. If image already fits the size no action in taken.- Parameters:
maxWidth
-maxHeight
-
-
serialize
public String serialize()
-
deserialize
public void deserialize(String stringRepresentation) throws IOException
- Throws:
IOException
-
-