save it into file firstImage img=...
int width = img.getWidth(null);
int height = img.getHeight(null);
BufferedImage bi = new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
Graphics g = bi.getGraphics();
g.drawImage(img,0,0,width,height,null);
g.dispose();
File f = new File("c:\\images\\myimage.png");
ImageIO.write(bi, "png", f);
int width = img.getWidth(null);
int height = img.getHeight(null);
BufferedImage bi = new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
Graphics g = bi.getGraphics();
g.drawImage(img,0,0,width,height,null);
g.dispose();
File f = new File("c:\\images\\myimage.png");
ImageIO.write(bi, "png", f);
解决方案 »
- 广州传智播客2012年3月28号javaEE+android完整课程实录视频
- j2ee菜鸟级问题
- 统计访问 100分
- JDK帮助文当中为什么没有dt.jar等jre环境中必需的类库的API说明
- Eclipse IDE for Java EE 开发j2ee程序还需要哪些插件
- 一个实际工作中遇到的问题 请教.................
- Spring 问题,请问下为什么加载不了配置文件
- struts下连接oracle数据库异常,如何配置?
- 方法java.net.Socket.getRemoteSocketAddress用的不爽!
- 工作四年了,现在有点迷茫。求指定一下!
- 关于struts ActionForm实例化的问题
- 麻烦大家给个java的电子文档
像OUTLOOK,FOXMAIL等客户端邮件接收器都是可以显示图片的。
mail.china.com 的邮件WEB 端也可以直接显示图片的。
如果你要直接编程实现图片直接显示。
网上有好多现成的资料,
好像是<meta> 这儿一设置,再把附件内容读到当前页面就可以了。
生成html格式的文件
然后再以附件的形式发过去
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;public class HtmlImageExample {
public static void main (String args[]) throws Exception {
String host = args[0];
String from = args[1];
String to = args[2];
String file = args[3]; // Get system properties
Properties props = System.getProperties(); // Setup mail server
props.put("mail.smtp.host", host); // Get session
Session session = Session.getDefaultInstance(props, null); // Create the message
Message message = new MimeMessage(session); // Fill its headers
message.setSubject("Embedded Image");
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to)); // Create your new message part
BodyPart messageBodyPart = new MimeBodyPart(); // Set the HTML content, be sure it references the attachment
String htmlText = "<H1>Hello</H1>" +
"<img src=\"cid:memememe\">"; // Set the content of the body part
messageBodyPart.setContent(htmlText, "text/html"); // Create a related multi-part to combine the parts
MimeMultipart multipart = new MimeMultipart("related"); // Add body part to multipart
multipart.addBodyPart(messageBodyPart); // Create part for the image
messageBodyPart = new MimeBodyPart(); // Fetch the image and associate to part
DataSource fds = new FileDataSource(file);
messageBodyPart.setDataHandler(new DataHandler(fds)); // Add a header to connect to the HTML
messageBodyPart.setHeader("Content-ID","<memememe>"); // Add part to multi-part
multipart.addBodyPart(messageBodyPart); // Associate multi-part with message
message.setContent(multipart); // Send message
Transport.send(message);
}
}使用:
java HtmlImageExample SMTP.Server from@address to@address filename