public class ImagesTools extends Object
┌─┐ ┌─┐
┌──┘ ┴───────┘ ┴──┐
│ │
│ ─── │
│ ─┬┘ └┬─ │
│ │
│ ─┴─ │
│ │
└───┐ ┌───┘
│ │
│ │
│ │
│ └──────────────┐
│ │
│ ├─┐
│ author:lelouch ┌─┘
│ │
└─┐ ┐ ┌───────┬──┐ ┌──┘
│ ─┤ ─┤ │ ─┤ ─┤
└──┴──┘ └──┴──┘
神兽保佑
代码无BUG!
| 构造器和说明 |
|---|
ImagesTools() |
| 限定符和类型 | 方法和说明 |
|---|---|
static void |
addWatermarkPic(BufferedImage bi,
BufferedImage icon,
int x,
int y)
文件水印(图片)
|
static void |
addWatermarkPic(BufferedImage bi,
BufferedImage icon,
int x,
int y,
float alph)
文件水印(图片)
|
static void |
addWatermarkText(BufferedImage bi,
Font font,
Color color,
String text,
int x,
int y,
float alph)
添加水印文字
|
static void |
addWatermarkText(BufferedImage bi,
String text,
int x,
int y)
添加水印文字
|
static String |
BufferedImageToBase64(BufferedImage bi,
String formatName)
BufferedImage To Base64
|
static byte[] |
BufferedImageToBytes(BufferedImage bi,
String formatName)
BufferedImage To Bytes
|
static InputStream |
bufferedImageToInputStream(BufferedImage image,
String formatName)
将BufferedImage转换为InputStream
|
static BufferedImage |
bytesToBufferedImage(byte[] bytes)
bytes To BufferedImage
|
static String |
createAsciiPic(File file)
图片转ascii字符
|
static BufferedImage |
cutPic(BufferedImage bi,
CutConfig cutConfig)
图片裁剪
|
static BufferedImage |
getBufferedImage(byte[] input)
获取 BufferedImage
|
static BufferedImage |
getBufferedImage(File pic)
获取 BufferedImage
|
static BufferedImage |
getBufferedImage(InputStream input)
获取 BufferedImage
|
static BufferedImage |
getBufferedImage(URL url)
获取 BufferedImage
|
static BufferedImage[] |
getBufferedImagex(byte[] bytes)
获取 BufferedImage(防偏色)
|
static BufferedImage[] |
getBufferedImagex(File pic)
获取 BufferedImage(防偏色)
|
static BufferedImage[] |
getBufferedImagex(InputStream input)
获取 BufferedImage(防偏色)
|
static String |
getImageFormatName(File file)
获取图片格式
|
static Image |
getScaledInstance(BufferedImage bi,
int width,
int height,
int hints)
图片缩放, 参数说明:
|
static BufferedImage |
getSubimage(BufferedImage bi,
int x,
int y,
int w,
int h)
裁剪图片, 参数说明:
|
static String |
getTypeByBytes(byte[] bytes)
根据文件流读取图片文件真实类型
|
static String |
getTypeByStream(FileInputStream is)
根据文件流读取图片文件真实类型
|
static BufferedImage |
grayPixel(BufferedImage bfimage) |
static BufferedImage |
jhlabs_filter(BufferedImage bi,
com.jhlabs.image.AbstractBufferedImageOp jhlabs)
滤镜处理
|
static int |
ostu(int[][] gray,
int w,
int h) |
static String |
QRString(File file)
二维码图片转ascii字符
|
static byte[] |
writeImageByte(BufferedImage bi,
String formatName)
写入 byte[]
|
static void |
writeImageFile(BufferedImage bi,
File outputfile)
写入文件
|
static void |
writeImageFileCompress(BufferedImage bi,
File outputfile)
压缩
|
static void |
writeImageFileCompress(BufferedImage bi,
File outputfile,
float Quality)
压缩
|
static InputStream |
writeImageInputStream(BufferedImage bi,
String formatName)
写入 InputStream
|
static BufferedImage |
zoomBufferedImage(BufferedImage image,
int width,
int height,
int hints)
例缩
|
public static BufferedImage grayPixel(BufferedImage bfimage)
public static int ostu(int[][] gray,
int w,
int h)
public static String getImageFormatName(File file) throws IOException
file - 图片文件IOExceptionpublic static BufferedImage getBufferedImage(File pic) throws IOException
pic - IOExceptionpublic static BufferedImage[] getBufferedImagex(File pic) throws SimpleImageException, IOException
pic - IOExceptionSimpleImageExceptionpublic static BufferedImage[] getBufferedImagex(byte[] bytes) throws SimpleImageException, IOException
bytes - IOExceptionSimpleImageExceptionpublic static BufferedImage[] getBufferedImagex(InputStream input) throws SimpleImageException, IOException
input - IOExceptionSimpleImageExceptionpublic static BufferedImage getBufferedImage(InputStream input) throws IOException
input - IOExceptionpublic static BufferedImage getBufferedImage(byte[] input) throws IOException
input - IOExceptionpublic static BufferedImage getBufferedImage(URL url) throws IOException
url - IOExceptionpublic static void writeImageFile(BufferedImage bi, File outputfile) throws IOException
bi - outputfile - IOExceptionpublic static InputStream writeImageInputStream(BufferedImage bi, String formatName) throws IOException
bi - formatName - IOExceptionpublic static byte[] writeImageByte(BufferedImage bi, String formatName)
bi - formatName - IOExceptionpublic static BufferedImage jhlabs_filter(BufferedImage bi, com.jhlabs.image.AbstractBufferedImageOp jhlabs)
bi - jhlabs - public static void writeImageFileCompress(BufferedImage bi, File outputfile)
bi - outputfile - public static void writeImageFileCompress(BufferedImage bi, File outputfile, float Quality)
bi - outputfile - Quality - 参数qality是取值0~1范围内,不要低于0.3f,不高于0.9fpublic static void addWatermarkText(BufferedImage bi, Font font, Color color, String text, int x, int y, float alph)
bi - font - color - text - x - y - alph - public static void addWatermarkPic(BufferedImage bi, BufferedImage icon, int x, int y, float alph)
bi - icon - x - y - alph - PressCSSpublic static void addWatermarkText(BufferedImage bi, String text, int x, int y)
bi - text - x - y - public static void addWatermarkPic(BufferedImage bi, BufferedImage icon, int x, int y)
bi - icon - x - y - PressCSSpublic static BufferedImage getSubimage(BufferedImage bi, int x, int y, int w, int h)
bi - x - 裁剪起点横坐标y - 裁剪起点纵坐标w - 需要裁剪的宽度h - 需要裁剪的高度public static Image getScaledInstance(BufferedImage bi, int width, int height, int hints)
bi - width - 缩放后的宽度height - 缩放后的高度hints - 指示用于图像重新取样的算法类型的标志
hints 参数取值为以下之一(Image 类中的常量): SCALE_AREA_AVERAGING: 使用 Area Averaging 图像缩放算法; SCALE_DEFAULT: 使用默认的图像缩放算法; SCALE_FAST: 选择一种图像缩放算法,在这种缩放算法中,缩放速度比缩放平滑度具有更高的优先级; SCALE_REPLICATE: 使用 ReplicateScaleFilter 类中包含的图像缩放算法; SCALE_SMOOTH: 选择图像平滑度比缩放速度具有更高优先级的图像缩放算法。
PS: 获取到的结果是 Image, 如果想转换为 BufferedImage, 可以创建一个相同宽高的空的 BufferedImage, 然后把获取到的 Image 绘制到 BufferedImage 上。
public static BufferedImage cutPic(BufferedImage bi, CutConfig cutConfig)
bi - cutConfig - PressCSSpublic static String getTypeByStream(FileInputStream is)
is - public static String getTypeByBytes(byte[] bytes)
is - public static String BufferedImageToBase64(BufferedImage bi, String formatName)
bi - formatName - public static BufferedImage bytesToBufferedImage(byte[] bytes) throws IOException
bytes - IOExceptionpublic static byte[] BufferedImageToBytes(BufferedImage bi, String formatName)
bi - formatName - public static InputStream bufferedImageToInputStream(BufferedImage image, String formatName)
image - formatName - public static BufferedImage zoomBufferedImage(BufferedImage image, int width, int height, int hints)
image - width - height - hints - BufferedImage.SCALE_SMOOTHCopyright © 2020. All rights reserved.