zoukankan      html  css  js  c++  java
  • java实现把两张图片合并(Graphics2D)

    package com.yin.text;
    
    import java.awt.Graphics2D;
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.IOException;
    
    import javax.imageio.ImageIO;
    
    /**
     * 把两张图片合并
     * @version 2018-2-27 上午11:12:09
     *
     */
    public class Picture1
    {
         private Graphics2D g        = null;  
          
        /**  
         * 导入本地图片到缓冲区  
         */  
        public BufferedImage loadImageLocal(String imgName) {  
            try {  
                return ImageIO.read(new File(imgName));  
            } catch (IOException e) {  
                System.out.println(e.getMessage());  
            }  
            return null;  
        } 
        
        public BufferedImage modifyImagetogeter(BufferedImage b, BufferedImage d) {  
            
            try {  
                int w = b.getWidth();  
                int h = b.getHeight();  
      
                g = d.createGraphics();  
                g.drawImage(b, 300, -800, w, h, null);  
                g.dispose();  
            } catch (Exception e) {  
                System.out.println(e.getMessage());  
            }  
      
            return d;  
        } 
        
        /**  
         * 生成新图片到本地  
         */  
        public void writeImageLocal(String newImage, BufferedImage img) {  
            if (newImage != null && img != null) {  
                try {  
                    File outputfile = new File(newImage);  
                    ImageIO.write(img, "jpg", outputfile);  
                } catch (IOException e) {  
                    System.out.println(e.getMessage());  
                }  
            }  
        } 
            
        public static void main(String[] args) {  
            
            Picture1 tt = new Picture1();  
      
            BufferedImage d = tt.loadImageLocal("C:/1.jpg");  
            BufferedImage b = tt.loadImageLocal("C:/11.jpg");
            
            tt.writeImageLocal("C:/new10.jpg", tt.modifyImagetogeter(b, d));    
            //将多张图片合在一起    
            System.out.println("success");  
        } 
    }
  • 相关阅读:
    ACdream 1224 Robbers (贪心)
    HDU 4320 Arcane Numbers 1 (质因子分解)
    在脚本中重定向输入
    呈现数据
    shell中的for、while、until(二)
    shell中的for、while、until
    C 指针疑虑
    结构化命令
    fdisk -c 0 350 1000 300命令
    PC机上的COM1口和COM2口
  • 原文地址:https://www.cnblogs.com/yinyl/p/8478352.html
Copyright © 2011-2022 走看看