zoukankan      html  css  js  c++  java
  • 图片合成

    private BufferedImage  compose (String  fileNameFront,String fileNameBack){
    	   BufferedImage frontImage;
    	   BufferedImage imageResult=null;
    	   try {
    		   long startFrontTime = System.currentTimeMillis();
    		   DefaultLogger.info("StartfrontImage============="+startFrontTime);
    		   frontImage = ImageIO.read(new File(fileNameFront));
    		   int width = frontImage.getWidth();// width 
    		   int height = frontImage.getHeight();// height
    		   int[] imageArrayFirst = new int[width * height];// RGB  
    		   imageArrayFirst = frontImage.getRGB(0, 0, width, height, imageArrayFirst, 0, width);  
    		   frontImage.flush();
    		   long startBackTime = System.currentTimeMillis();
    		   DefaultLogger.info("frontImageTime============="+(startBackTime-startFrontTime));
    		   
    		   BufferedImage backImage = ImageIO.read(new File(fileNameBack));
    		   int widthBack = backImage.getWidth();// width 
    		   int heightBack = backImage.getHeight();// height		   
    		   int[] imageArraySecond = new int[widthBack * heightBack];  
    		   imageArraySecond = backImage.getRGB(0, 0, widthBack, heightBack, imageArraySecond, 0, widthBack); 
    		   backImage.flush();
    		   long endBackTime = System.currentTimeMillis();
    		   DefaultLogger.info("backImageTime============="+(endBackTime-startBackTime));
    		   // new image   
    		   imageResult = new BufferedImage(width, height * 2+3,BufferedImage.TYPE_INT_RGB); 
    		   //config images Transparency
    		   Graphics2D g2d = imageResult.createGraphics();
    		   imageResult = g2d.getDeviceConfiguration().createCompatibleImage(width, height* 2+3, Transparency.TRANSLUCENT);
    		   g2d.dispose();
    		   
    		   imageResult.setRGB(0, 0, width, height, imageArrayFirst, 0, width);// set above RGB  
    		   imageResult.setRGB(0, height+3, width, height, imageArraySecond, 0, width);// set below RGB  
    		  
    		   imageResult.flush();
    		   long imageTime = System.currentTimeMillis();
    		   DefaultLogger.info("ImageTime============="+(imageTime-endBackTime));
    		   DefaultLogger.info("Form FrontImage To Image============="+(imageTime-startFrontTime));
    		   
    	   } catch (IOException e1) {
    		// TODO Auto-generated catch block
    		e1.printStackTrace();
    	   } 
    	   
    	   
    	   return imageResult;
    	   }
    	
    	//vertical compose image
    	private BufferedImage compose2 (String  fileNameFront,String fileNameBack){
    		BufferedImage frontImage;
    		 BufferedImage combined=null;
    		try {
    			frontImage = ImageIO.read(new File(fileNameFront));
    			BufferedImage backImage = ImageIO.read(new File(fileNameBack));
    		       combined = new BufferedImage(frontImage.getWidth() , frontImage.getHeight()*2, BufferedImage.TYPE_INT_RGB);  
    		       
    		       
    		       Graphics g = combined.getGraphics();  
    		       g.drawImage(frontImage, 0, 0, null);  
    		       g.drawImage(backImage, 0, frontImage.getHeight(), null); 
    		} catch (IOException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    		 
         
           return combined;
    		
    	}
    

      合成大小相同图片

  • 相关阅读:
    [Angular] HostListener Method Arguments
    [Docker] Create Docker Volumes for Persistent Storage
    [Algorithms] Binary Search Algorithm using TypeScript
    [Node] Setup an Nginx Proxy for a Node.js App
    [Node] Run Local DevDependencies from the Command Line with npx
    [HTML] Change an HTML5 input's placeholder color with CSS
    [Node] Run Any Version of a Node Tool with npx
    [Angular] Learn How To Use ng-template Inputs
    [Angular] Learn Angular Multi-Slot Content Projection
    Jquery读取URL参数
  • 原文地址:https://www.cnblogs.com/jingRegina/p/5527884.html
Copyright © 2011-2022 走看看