整理文档,搜刮出一个java实现切图并且判断图片是否是纯色/彩色图片的代码,稍微整理精简一下做下分享。首先上切图的代码 public static void imageCut(int x, int y, int width, int he
整理文档,搜刮出一个java实现切图并且判断图片是否是纯色/彩色图片的代码,稍微整理精简一下做下分享。
首先上切图的代码
public static void imageCut(int x, int y, int width, int height, String sourcePath, String descpath) { 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, width, height); 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; } } }
--结束END--
本文标题: java实现切图并且判断图片是不是纯色/彩色图片
本文链接: https://lsjlt.com/news/224193.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0