java进行多张图片组合一张图片

</pre><pre name="code" class="java">package com.han.demo;


import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.net.URL;


import javax.imageio.ImageIO;
import javax.jws.soap.SOAPBinding.Style;


public class Test{
	/**
	 * 将图片进行合成
	 * @param bigPath 主图图片路径
	 * @param smallPath 商品图片路径
	 * @param erweimaPath 二维码图片路径
	 */
	public static final void overlapImage(String bigPath, String smallPath,String erweimaPath) {
	    try {
	      BufferedImage big = ImageIO.read(new File(bigPath));
	      URL url = new URL("图片URL访问地址"); 
	      BufferedImage small = ImageIO.read(url.openStream());
	      BufferedImage erweima = ImageIO.read(new File(erweimaPath));
	      int width=2015; 
		  int height=1136;
		  Image image=big.getScaledInstance(width, height, Image.SCALE_SMOOTH);
		  BufferedImage bufferedImage2=new BufferedImage(width, height, BufferedImage.TYPE_INT_BGR);
	      Graphics2D g = bufferedImage2.createGraphics();
	      int x = 707;
	      int y = 268;
	      int x1 = 684;
	      int y1 = 245;
	      g.drawImage(image, 0, 0,null);
	      g.drawImage(small, x+320, y-5, 800, 600, null);
	      g.drawImage(erweima, x1-575, y1+100, 596, 596, null);
	      Font font=new Font("宋体",Font.PLAIN , 40);
	      g.setFont(font);
	      g.setPaint(Color.DARK_GRAY);
		  int numWidth =x+320;
		  int numHright=y+650;
		  int num=0;
	      g.drawString("商品名称:" , numWidth,numHright);  
	      num += 50;  
	      g.setPaint(Color.DARK_GRAY);
	      Font font1=new Font("宋体",Font.BOLD , 40);
	      g.setFont(font1);
	      g.drawString("售价:", numWidth,numHright+num); 
	      num += 50; 
	      Font font2=new Font("宋体",Font.PLAIN , 40);
	      g.setFont(font2);
	      g.setPaint(Color.DARK_GRAY);
	      g.drawString("原产地:", numWidth, numHright+num); 
	      num += 50;  
	      g.drawString("配送方式:",numWidth, numHright+num); 
	      g.dispose();
	      ImageIO.write(bufferedImage2, "jpg", new File("e:\\hehe.jpg"));
	    } catch (Exception e) {
	      e.printStackTrace();
	    }
	  }
	  public static final void main(String[] args) {
	    overlapImage("e:\\ps.png", "e:\\m.jpg","e:\\n.jpg");
	  }


}
<img src="https://img-blog.csdn.net/20150906104118760" alt="" />


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值