public class ImageUtil extends java.lang.Object
Constructor and Description |
---|
ImageUtil() |
Modifier and Type | Method and Description |
---|---|
static java.awt.image.BufferedImage |
copy(java.awt.image.BufferedImage src)
创建
BufferedImage.TYPE_3BYTE_BGR 类型的拷贝 |
static java.awt.image.BufferedImage |
copy(java.awt.Image src,
int imageType)
从源
BufferedImage 对象创建一份拷贝 |
static byte[] |
createJPEGThumbnail(byte[] imageBytes,
int thumbnailWidth,
int thumbnailHeight,
double ratioThreshold)
对原图创建JPEG格式的缩略图
|
static java.awt.image.BufferedImage |
createRGBAImage(byte[] matrixRGBA,
int width,
int height)
从RGBA格式图像矩阵数据创建一个BufferedImage
该方法删除了alpha通道 |
static java.awt.image.BufferedImage |
createRGBImage(byte[] matrixRGB,
int width,
int height)
从RGB格式图像矩阵数据创建一个BufferedImage
|
static java.awt.image.BufferedImage |
createThumbnail(java.awt.image.BufferedImage source,
int thumbnailWidth,
int thumbnailHeight,
double ratioThreshold)
对原图创建缩略图对象
如果原图尺寸小于指定的缩略图尺寸则直接返回原图对象的副本 |
static byte[] |
cutMatrix(byte[] matrix,
java.awt.Rectangle matrixRect,
java.awt.Rectangle rect)
从matrix矩阵中截取rect指定区域的子矩阵
|
static byte[] |
getMatrixBGR(java.awt.image.BufferedImage image)
对图像解码返回BGR格式矩阵数据
|
static byte[] |
getMatrixGRAY(java.awt.image.BufferedImage image)
对图像解码返回BGR格式矩阵数据
|
static byte[] |
getMatrixRGB(java.awt.image.BufferedImage image)
对图像解码返回RGB格式矩阵数据
|
static byte[] |
getMatrixRGBA(java.awt.image.BufferedImage image)
对图像解码返回RGB格式矩阵数据
|
static java.awt.image.BufferedImage |
growCanvas(java.awt.Image src,
int left,
int top,
int right,
int bottom) |
static java.awt.image.BufferedImage |
growCanvas(java.awt.Image src,
int imageType,
int left,
int top,
int right,
int bottom)
将
Image 图像上下左右扩充指定的尺寸 |
static java.awt.image.BufferedImage |
growSquareCanvas(java.awt.Image src)
将
Image 图像(向右下)扩充为正文形(尺寸长宽最大边) |
static boolean |
isBGR3Byte(java.awt.image.BufferedImage image) |
static boolean |
isBGRA(java.awt.image.BufferedImage image) |
static boolean |
isGray(java.awt.image.BufferedImage image) |
static boolean |
isRGB3Byte(java.awt.image.BufferedImage image) |
static java.awt.image.BufferedImage |
resize(java.awt.image.BufferedImage source,
int targetWidth,
int targetHeight,
boolean constrain)
对图像进行缩放
|
static java.awt.image.BufferedImage |
scale(java.awt.image.BufferedImage src,
double scale)
对原图缩放,返回缩放后的新对象
|
static void |
wirte(java.awt.image.BufferedImage source,
java.lang.String formatName,
java.lang.Float compressionQuality,
java.io.OutputStream output)
将
BufferedImage 生成formatName指定格式的图像数据 |
static byte[] |
wirteBMPBytes(java.awt.image.BufferedImage source) |
static byte[] |
wirteBytes(java.awt.image.BufferedImage source,
java.lang.String formatName) |
static byte[] |
wirteBytes(java.awt.image.BufferedImage source,
java.lang.String formatName,
java.lang.Float compressionQuality)
将
BufferedImage 生成formatName指定格式的图像数据 |
static byte[] |
wirteGIFBytes(java.awt.image.BufferedImage source) |
static byte[] |
wirteJPEGBytes(java.awt.image.BufferedImage source) |
static byte[] |
wirteJPEGBytes(java.awt.image.BufferedImage source,
java.lang.Float compressionQuality)
将原图压缩生成jpeg格式的数据
|
static byte[] |
wirtePNGBytes(java.awt.image.BufferedImage source) |
static boolean |
write(java.awt.image.RenderedImage source,
java.lang.String formatName,
java.io.OutputStream output,
java.lang.Float compressionQuality)
将原图压缩生成
formatName 指定格式的数据除了可以指定生成的图像质量之外, 其他行为与 ImageIO.write(RenderedImage, String, OutputStream) 相同 |
public ImageUtil()
public static java.awt.image.BufferedImage resize(java.awt.image.BufferedImage source, int targetWidth, int targetHeight, boolean constrain)
source
- 原图targetWidth
- 缩放后图像宽度targetHeight
- 缩放后图像高度constrain
- 为true时等比例缩放,targetWidth,targetHeight为缩放图像的限制尺寸public static byte[] wirteJPEGBytes(java.awt.image.BufferedImage source)
public static byte[] wirteBMPBytes(java.awt.image.BufferedImage source)
public static byte[] wirtePNGBytes(java.awt.image.BufferedImage source)
public static byte[] wirteGIFBytes(java.awt.image.BufferedImage source)
public static byte[] wirteJPEGBytes(java.awt.image.BufferedImage source, java.lang.Float compressionQuality)
source
- wirteBytes(BufferedImage, String)
public static byte[] wirteBytes(java.awt.image.BufferedImage source, java.lang.String formatName)
public static byte[] wirteBytes(java.awt.image.BufferedImage source, java.lang.String formatName, java.lang.Float compressionQuality)
BufferedImage
生成formatName指定格式的图像数据source
- formatName
- 图像格式名,图像格式名错误则抛出异常,可用的值 'BMP','PNG','GIF','JPEG'compressionQuality
- 压缩质量(0.0~1.0),超过此范围抛出异常,为null使用默认值public static void wirte(java.awt.image.BufferedImage source, java.lang.String formatName, java.lang.Float compressionQuality, java.io.OutputStream output) throws java.io.IOException
BufferedImage
生成formatName指定格式的图像数据source
- formatName
- 图像格式名,图像格式名错误则抛出异常,可用的值 'BMP','PNG','GIF','JPEG'compressionQuality
- 压缩质量(0.0~1.0),超过此范围抛出异常,为null使用默认值output
- 输出流java.io.IOException
public static java.awt.image.BufferedImage createThumbnail(java.awt.image.BufferedImage source, int thumbnailWidth, int thumbnailHeight, double ratioThreshold)
source
- 原图对象thumbnailWidth
- 缩略图宽度thumbnailHeight
- 缩略图高度ratioThreshold
- 最大宽高比阀值(宽高中较大的值/较小的值),<此值时对原图等比例缩放,>=此值时从原图切出中间部分图像再等比例缩放public static byte[] createJPEGThumbnail(byte[] imageBytes, int thumbnailWidth, int thumbnailHeight, double ratioThreshold)
imageBytes
- 图像数据字节数组thumbnailWidth
- thumbnailHeight
- ratioThreshold
- createThumbnail(BufferedImage, int, int, double)
,
wirteJPEGBytes(BufferedImage)
public static boolean isBGRA(java.awt.image.BufferedImage image)
public static boolean isGray(java.awt.image.BufferedImage image)
public static boolean isBGR3Byte(java.awt.image.BufferedImage image)
public static boolean isRGB3Byte(java.awt.image.BufferedImage image)
public static byte[] getMatrixRGB(java.awt.image.BufferedImage image)
image
- public static byte[] getMatrixRGBA(java.awt.image.BufferedImage image)
image
- public static byte[] getMatrixBGR(java.awt.image.BufferedImage image)
image
- public static byte[] getMatrixGRAY(java.awt.image.BufferedImage image)
image
- public static java.awt.image.BufferedImage copy(java.awt.Image src, int imageType)
BufferedImage
对象创建一份拷贝src
- imageType
- 创建的BufferedImage
目标对象类型BufferedImage.BufferedImage(int, int, int)
public static java.awt.image.BufferedImage copy(java.awt.image.BufferedImage src)
BufferedImage.TYPE_3BYTE_BGR
类型的拷贝src
- copy(Image, int)
public static java.awt.image.BufferedImage scale(java.awt.image.BufferedImage src, double scale)
src
- scale
- public static java.awt.image.BufferedImage growCanvas(java.awt.Image src, int imageType, int left, int top, int right, int bottom)
Image
图像上下左右扩充指定的尺寸src
- imageType
- left
- top
- right
- bottom
- public static java.awt.image.BufferedImage growCanvas(java.awt.Image src, int left, int top, int right, int bottom)
src
- left
- top
- right
- bottom
- growCanvas(Image, int, int, int, int, int)
public static java.awt.image.BufferedImage growSquareCanvas(java.awt.Image src)
Image
图像(向右下)扩充为正文形(尺寸长宽最大边)src
- public static boolean write(java.awt.image.RenderedImage source, java.lang.String formatName, java.io.OutputStream output, java.lang.Float compressionQuality) throws java.io.IOException
formatName
指定格式的数据ImageIO.write(RenderedImage, String, OutputStream)
相同source
- formatName
- output
- compressionQuality
- 指定图像质量,为null
调用ImageIO.write(RenderedImage, String, OutputStream)
java.io.IOException
public static java.awt.image.BufferedImage createRGBImage(byte[] matrixRGB, int width, int height)
matrixRGB
- RGB格式图像矩阵数据,为null则创建一个指定尺寸的空图像width
- height
- public static java.awt.image.BufferedImage createRGBAImage(byte[] matrixRGBA, int width, int height)
matrixRGBA
- RGBA格式图像矩阵数据,为null则创建一个指定尺寸的空图像width
- height
- public static byte[] cutMatrix(byte[] matrix, java.awt.Rectangle matrixRect, java.awt.Rectangle rect)
matrix
- 3byte(RGB/BGR) 图像矩阵matrixRect
- 矩阵尺寸rect
- 截取区域Copyright © 2019. All rights reserved.