zoukankan      html  css  js  c++  java
  • java 图片合成(子图已经优化)

    底层工具类,参数为文件流,返回也是文件流,具体是上传云还是下载这里就不写了,主要是图片合成

    业务是一张底图,一张或者多张子图片,更具子图的坐标x和坐标y生成图片

    PictureSynthesisSonFo 对象为子图对象
    PictureSynthesisFo 对象为底图对象并包含子图对象集合
    public static InputStream overlapImage(PictureSynthesisFo pictureSynthesisFo){
            InputStream is;
            try {
                //设置图片大小
                //背景图片
                BufferedImage background = ImageIO.read(pictureSynthesisFo.getInputStream());
                Graphics2D g = background.createGraphics();
                g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BILINEAR);
                g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 1));
                for (PictureSynthesisSonFo sonFiles : pictureSynthesisFo.getSonFiles()  ) {
                    BufferedImage qrCode = ImageIO.read(sonFiles.getInputStream());
                    log.info("合成签字图fileCode:{},原{},{},原height:{},height:{}",sonFiles.getFileCode(),
                            qrCode.getWidth(),sonFiles.getWidth(),qrCode.getHeight(), sonFiles.getHeight());
                    //在背景图片上添加图片
                    g.drawImage(qrCode .getScaledInstance(sonFiles.getWidth(), sonFiles.getHeight(), Image.SCALE_SMOOTH),  sonFiles.getX(), sonFiles.getY(), null);
                }
                g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER));
                g.dispose();
                ByteArrayOutputStream bs =new ByteArrayOutputStream();
                is = new ByteArrayInputStream(bs.toByteArray());
                return  is ;
            }catch (Exception e){
                LogUtil.error(log,"图片转换错误:{0}",e);
            }
            return null;
        }
  • 相关阅读:
    HTML与用户的交互 表单
    HTML区块元素与网页布局
    css清除浮动
    gulp 配置前端项目打包
    React Ntive 学习手记
    gulp 配置自动化前端开发
    HTML5调用手机相机拍照
    JQuery 1.8.3对IE9兼容问题getAttribute
    gruntJs篇之connect+watch自动刷新
    360安全浏览器浏览模式调整
  • 原文地址:https://www.cnblogs.com/mytzq/p/13553672.html
Copyright © 2011-2022 走看看