类 ImageUtility
- java.lang.Object
-
- tech.testnx.cah.common.utils.ImageUtility
-
public class ImageUtility extends Object
- 作者:
- Yun
-
-
字段概要
字段 修饰符和类型 字段 说明 static ImageUtilityINSTANCE
-
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 byte[]convertToBytesFromImage(BufferedImage image)Convert an image to byte arrayBufferedImagecropImage(BufferedImage image, Rectangle rect)Crop or Resize an imagebooleanimageComparer(File expectedImage, File actualImage, File diffImage, int colorDistance, int pixelThreshold, StringBuilder resultMessage)API: Compare two images and highlight the differ image
If diffImage is null, will not produce differ image
If diffImage is not null, the differ image with RED highlight
"colorDistance", it means that the distance(difference) of two color can be acceptable.BufferedImagemergeImagesBySameWidth(List<BufferedImage> images)Merge images with same widthBufferedImagereadImageFromBytes(byte[] imageBytes)Read image from bytes arrayBufferedImagereadImageFromFile(File file)Read image from file
-
-
-
字段详细资料
-
INSTANCE
public static final ImageUtility INSTANCE
-
-
方法详细资料
-
imageComparer
public boolean imageComparer(File expectedImage, File actualImage, File diffImage, int colorDistance, int pixelThreshold, StringBuilder resultMessage) throws Exception
API: Compare two images and highlight the differ image
If diffImage is null, will not produce differ image
If diffImage is not null, the differ image with RED highlight
"colorDistance", it means that the distance(difference) of two color can be acceptable. if set 0, then color must be completely same. The value should be greater than or equal 0;
"pixelThreshold", it means that how many the unmatched pixels can be acceptable. if set 0, only all pixels are same, return TRUE. The value should be greater than or equal 0;
If dimensions of two images are different, then return FALSE and the differ image is merged by two original images.
Note: only support image types: GIF, PNG, JPEG, BMP, and WBMP- 抛出:
Exception
-
readImageFromBytes
public BufferedImage readImageFromBytes(byte[] imageBytes) throws IOException
Read image from bytes array- 抛出:
IOException
-
readImageFromFile
public BufferedImage readImageFromFile(File file) throws IOException
Read image from file- 抛出:
IOException
-
cropImage
public BufferedImage cropImage(BufferedImage image, Rectangle rect)
Crop or Resize an image
-
convertToBytesFromImage
public byte[] convertToBytesFromImage(BufferedImage image) throws IOException
Convert an image to byte array- 抛出:
IOException
-
mergeImagesBySameWidth
public BufferedImage mergeImagesBySameWidth(List<BufferedImage> images)
Merge images with same width
-
-