Class ImageCompressor
java.lang.Object
com.markvarga21.studentmanager.util.ImageCompressor
A class which is used to compress images.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
The maximum file size accepted by the database in bytes.static final float
The scale of which the image is decreased in each step. -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]
compressImage
(org.springframework.web.multipart.MultipartFile image) Compresses the given image.static byte[]
toByteArray
(BufferedImage bi, String format) Converts the given image to a byte array.
-
Field Details
-
SCALE_DECREASE_STEP
public static final float SCALE_DECREASE_STEPThe scale of which the image is decreased in each step.- See Also:
-
DEFAULT_SIZE_LIMIT
public static final int DEFAULT_SIZE_LIMITThe maximum file size accepted by the database in bytes.- See Also:
-
-
Method Details
-
toByteArray
Converts the given image to a byte array.- Parameters:
bi
- The image to be converted.format
- The format of the image.- Returns:
- The byte array of the image.
- Throws:
IOException
- If the image cannot be written.
-
compressImage
public static byte[] compressImage(org.springframework.web.multipart.MultipartFile image) Compresses the given image.- Parameters:
image
- The image to compress.- Returns:
- The compressed image.
-