zoukankan      html  css  js  c++  java
  • 图片截取(裁剪)

        public static void cutImage(File file) {
            String fileName = file.getPath();
            String lastName = fileName.substring(fileName.lastIndexOf(".") + 1,fileName.length());
            FileInputStream fis = null;
            ImageInputStream iis = null;
            try {
                /**读取图片*/
                Iterator<ImageReader> it = ImageIO.getImageReadersByFormatName(lastName);
                ImageReader reader = it.next();
                /**获取图片流*/
                fis = new FileInputStream(file);
                iis = ImageIO.createImageInputStream(fis);
                reader.setInput(iis, true);

                ImageReadParam param = reader.getDefaultReadParam();
                BufferedImage image = null;
                image = ImageIO.read(file);
                int width = image.getWidth();
                int height = image.getHeight();
                Rectangle rect;
                if (300 < height) {
                    rect = new Rectangle(0, 0, width, height-50);
                } else {
                    rect = new Rectangle(0, 0, width, height);
                }
                param.setSourceRegion(rect);
                BufferedImage bi = reader.read(0, param);

                ImageIO.write(bi, lastName, file);
            } catch (Exception ex) {
                ex.printStackTrace();
            } finally {
                try {
                    if (fis != null) {
                        fis.close();
                    }
                    if (iis != null) {
                        iis.close();
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        }

  • 相关阅读:
    3js深入
    01课js初接触;
    弥合对象/关系之间的鸿沟(一)
    Spiral Matrix——螺旋矩阵
    原来···是不是高手,看try cathch都能看出来···
    Web视频分享处理类库的设计
    每个开发人员现在应该下载的十种必备工具
    使用C#得到局域网内所有主机名,IP地址,MAC地址,使用C# 实现查看所有系统事件
    IIS 错误 :“NETWORK SERVICE does not have write access” 解决办法
    配置Url Remap时发生Parser Error的解决办法
  • 原文地址:https://www.cnblogs.com/sand-tiny/p/3582794.html
Copyright © 2011-2022 走看看