public class ImageUtil extends Object
| 构造器和说明 |
|---|
ImageUtil() |
| 限定符和类型 | 方法和说明 |
|---|---|
static BufferedImage |
bigImage(BufferedImage originalImage,
Integer times)
对图片进行放大
|
static byte[] |
bufferedImageToByte(BufferedImage bufferedImage,
String imageSuffix)
将
BufferedImage 转换为 Byte[] |
static InputStream |
bufferedImageToInputStream(BufferedImage bufferedImage,
String imageFileSuffix)
将
BufferedImage 转换为 InputStream |
static BufferedImage |
formatConversion(BufferedImage bufferedImage)
后缀格式转换,读入 png、jpg、gif格式图片的
BufferedImage ,返回新生成的内存图像,可另行保存为png、jpg、gif等格式 |
static BufferedImage |
getBufferedImageByUrl(String imageUrl)
通过一个图片所在的URL超链接,读取图片的 BufferedImage
|
static String |
getImageType(byte[] imageBytes)
获取图片的类型。
|
static BufferedImage |
inputStreamToBufferedImage(InputStream is)
将
InputStream 转化为 BufferedImage |
static byte[] |
inputStreamToByte(InputStream is)
将
InputStream 转换为 Byte[] |
static BufferedImage |
loadLocalhostImage(String path)
加载本地图像,变为
BufferedImage |
static BufferedImage |
proportionZoom(BufferedImage bufferedImage,
int maxWidth)
等比例缩放
判断图像的宽度,若是宽度大于传入的值,则进行等比例压缩到指定宽高。
|
static InputStream |
proportionZoom(InputStream inputStream,
int maxWidth,
String suffix)
等比例缩放
判断图像的宽度,若是宽度大于传入的值,则进行等比例压缩到指定宽高。
|
static BufferedImage |
replaceColor(BufferedImage bufferedImage,
String oldHex,
String newHex)
替换
BufferedImage中,制定颜色进行替换,比如将图片中所有红色的像素点替换为黑色 |
static void |
saveToLocalhost(BufferedImage bufferedImage,
String formatName,
String path)
将
BufferedImage 保存到本地 |
static BufferedImage |
watermark(BufferedImage originalImage,
BufferedImage shuiyinImage,
int startX,
int startY,
int width,
int height)
图片水印
|
public static BufferedImage replaceColor(BufferedImage bufferedImage, String oldHex, String newHex)
BufferedImage中,制定颜色进行替换,比如将图片中所有红色的像素点替换为黑色bufferedImage - 要替换的图像oldHex - 要替换的像素点十六进制颜色,如FFFFFFnewHex - 替换成的新颜色,像素点十六进制颜色,如FFFFFFBufferedImagepublic static BufferedImage bigImage(BufferedImage originalImage, Integer times)
originalImage - 原始图片times - 放大倍数public static InputStream proportionZoom(InputStream inputStream, int maxWidth, String suffix)
判断图像的宽度,若是宽度大于传入的值,则进行等比例压缩到指定宽高。若是图片小于指定的值,则不处理
inputStream - 原图maxWidth - 缩放后的宽度。若大于这个宽度才会进行等比例缩放。否则不进行处理。传入0则不处理,忽略suffix - 图片的后缀名,如png、jpgpublic static BufferedImage proportionZoom(BufferedImage bufferedImage, int maxWidth)
判断图像的宽度,若是宽度大于传入的值,则进行等比例压缩到指定宽高。若是图片小于指定的值,则不处理
bufferedImage - 原图maxWidth - 缩放后的宽度。若大于这个宽度才会进行等比例缩放。否则不进行处理public static BufferedImage getBufferedImageByUrl(String imageUrl)
imageUrl - 图片的URL超链接地址,如 http://www.leimingyun.com/a.jpgBufferedImagepublic static BufferedImage inputStreamToBufferedImage(InputStream is)
InputStream 转化为 BufferedImageis - 目标图片的InputStreamBufferedImagepublic static byte[] inputStreamToByte(InputStream is)
InputStream 转换为 Byte[]is - 目标图片的InputStreamByte[]public static String getImageType(byte[] imageBytes)
imageBytes - 图片字节数组。public static InputStream bufferedImageToInputStream(BufferedImage bufferedImage, String imageFileSuffix)
BufferedImage 转换为 InputStreambufferedImage - 要转换的 BufferedImageimageFileSuffix - 图片的后缀名,如 gif 、png 、 jpg 、 bmppublic static byte[] bufferedImageToByte(BufferedImage bufferedImage, String imageSuffix)
BufferedImage 转换为 Byte[]bufferedImage - 要转换的 BufferedImageimageSuffix - 图片的后缀名,如 gif 、png 、 jpg 、 bmpByte[] ,若是出错或没有,返回nullpublic static BufferedImage loadLocalhostImage(String path)
BufferedImagepath - 图像所在路径,如 : /images/ceshi.pngBufferedImage 若为空或图像不存在,返回nullpublic static void saveToLocalhost(BufferedImage bufferedImage, String formatName, String path)
BufferedImage 保存到本地bufferedImage - 要保存的内存图像formatName - 如 jpg、 png、gifpath - 本地路径,如 /images/xnx3/ceshiaaaa.pngpublic static BufferedImage formatConversion(BufferedImage bufferedImage)
BufferedImage ,返回新生成的内存图像,可另行保存为png、jpg、gif等格式bufferedImage - 要输入的图片的 BufferedImageBufferedImagepublic static BufferedImage watermark(BufferedImage originalImage, BufferedImage shuiyinImage, int startX, int startY, int width, int height)
originalImage - 原图,大图。比如,可用 getBufferedImageByUrl(String) 获取shuiyinImage - 水印图,小图,要水印到大图的水印图。startX - 水印开始地点,原图的左上角,X坐标startY - 水印开始地点,原图的左上角,Y坐标width - 宽度的像素点,会将整个图片压缩或放大整个图水印上。height - 高度的像素点BufferedImage 对象Copyright © 2019. All rights reserved.