81,092
社区成员
发帖
与我相关
我的任务
分享
<%@page import="java.awt.*"%>
<%@page import="java.awt.image.*"%>
<%@page import="com.sun.image.codec.jpeg.*"%>
<%@page import="javax.imageio.*" %>
public static void addPhotoFrame (String framPicName, String srcPicName, String outputPicName) throws Exception {
//相框文件
File framePicFile = new File(framPicName);
Image framePic = ImageIO.read(framePicFile);
int width = framePic.getWidth(null);
int height = framePic.getHeight(null);
BufferedImage image=new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics g = image.createGraphics();
g.drawImage(framePic, 0, 0, width, height, null);
//原图片文件
File srcPicFile = new File(srcPicName);
Image srcPic = ImageIO.read(srcPicFile);
int srcWidth = srcPic.getWidth(null);
int srcHeight = srcPic.getHeight(null);
g.drawImage(srcPic, 0, 6, srcWidth, srcHeight, null);
g.dispose();
FileOutputStream out = new FileOutputStream(outputPicName);
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
encoder.encode(image);
out.close();
}
addPhotoFrame("2.jpg","1.jpg","3.jpg");
<%@page import="java.awt.*"%>
<%@page import="java.io.*"%>
<%@page import="java.awt.image.*"%>
<%@page import="com.sun.image.codec.jpeg.*"%>
<%@page import="javax.imageio.*" %>
<%@page import="java.awt.*"%>
<%@page import="java.util.*"%>
<%!
public static void addPhotoFrame (String framPicName, String srcPicName, String outputPicName) throws Exception {
//相框文件
File framePicFile = new File(framPicName);
Image framePic = ImageIO.read(framePicFile);
int width = framePic.getWidth(null);
int height = framePic.getHeight(null);
BufferedImage image=new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics g = image.createGraphics();
g.drawImage(framePic, 0, 0, width, height, null);
//原图片文件
File srcPicFile = new File(srcPicName);
Image srcPic = ImageIO.read(srcPicFile);
int srcWidth = srcPic.getWidth(null);
int srcHeight = srcPic.getHeight(null);
g.drawImage(srcPic, 0, 6, srcWidth, srcHeight, null);
g.dispose();
FileOutputStream out = new FileOutputStream(outputPicName);
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
encoder.encode(image);
out.close();
}
%>
<%
addPhotoFrame("2.jpg","1.jpg","3.jpg");
%>