java 切图 判断图片是否是纯色/彩色图片
/*** 图片剪裁
*
@param x 距离左上角的x轴距离
*
@param y 距离左上角的y轴距离
*
@param>
*@param>
*@param sourcePath 图片源
*
@param descpath 目标位置
*/
public static void imageCut(int x, int y, int>
FileInputStream is = null;
ImageInputStream iis = null;
try {
is = new FileInputStream(sourcePath);
String fileSuffix = sourcePath.substring(sourcePath.lastIndexOf(".") + 1);
Iterator<ImageReader> it = ImageIO.getImageReadersByFormatName(fileSuffix);
ImageReader reader = it.next();
iis = ImageIO.createImageInputStream(is);
reader.setInput(iis, true);
ImageReadParam param = reader.getDefaultReadParam();
Rectangle rect = new Rectangle(x, y,>
param.setSourceRegion(rect);
BufferedImage bi = reader.read(0, param);
ImageIO.write(bi, fileSuffix, new File(descpath));
} catch (Exception ex) {
ex.printStackTrace();
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
is = null;
}
if (iis != null) {
try {
iis.close();
} catch (IOException e) {
e.printStackTrace();
}
iis = null;
}
}
}
页:
[1]