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;
        }
  • 相关阅读:
    Linux下chkconfig命令详解
    几种主流的快照技术
    HANA内存数据库与oracle数据库的性能比较
    计算机网络知识汇总
    bzoj1211: [HNOI2004]树的计数 prufer序列裸题
    1003: [ZJOI2006]物流运输 最短路+dp
    HDU
    2243: [SDOI2011]染色 树链剖分+线段树染色
    bzoj1036: [ZJOI2008]树的统计Count 树链剖分
    bzoj1042: [HAOI2008]硬币购物 dp+容斥
  • 原文地址:https://www.cnblogs.com/mytzq/p/13553672.html
Copyright © 2011-2022 走看看