惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

GbyAI
GbyAI
Cyberwarzone
Cyberwarzone
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
W
WeLiveSecurity
博客园 - 叶小钗
Hugging Face - Blog
Hugging Face - Blog
Security Latest
Security Latest
Scott Helme
Scott Helme
TaoSecurity Blog
TaoSecurity Blog
N
Netflix TechBlog - Medium
爱范儿
爱范儿
Application and Cybersecurity Blog
Application and Cybersecurity Blog
G
Google Developers Blog
F
Fortinet All Blogs
N
News and Events Feed by Topic
V2EX - 技术
V2EX - 技术
Google Online Security Blog
Google Online Security Blog
L
LINUX DO - 热门话题
NISL@THU
NISL@THU
The GitHub Blog
The GitHub Blog
Spread Privacy
Spread Privacy
S
Secure Thoughts
T
Tailwind CSS Blog
Google DeepMind News
Google DeepMind News
Recorded Future
Recorded Future
N
News and Events Feed by Topic
SecWiki News
SecWiki News
S
Security @ Cisco Blogs
A
About on SuperTechFans
云风的 BLOG
云风的 BLOG
L
Lohrmann on Cybersecurity
P
Palo Alto Networks Blog
Know Your Adversary
Know Your Adversary
IT之家
IT之家
人人都是产品经理
人人都是产品经理
Attack and Defense Labs
Attack and Defense Labs
Hacker News - Newest:
Hacker News - Newest: "LLM"
MyScale Blog
MyScale Blog
宝玉的分享
宝玉的分享
T
The Blog of Author Tim Ferriss
H
Hacker News: Front Page
T
Tenable Blog
C
CERT Recently Published Vulnerability Notes
D
DataBreaches.Net
阮一峰的网络日志
阮一峰的网络日志
Help Net Security
Help Net Security
博客园_首页
S
Securelist
罗磊的独立博客

博客园 - 空空色色

转一篇,CentOS后台服务配置 linux kernel 2.6.36 编译升级 linux的UPNP支持(转) UPNP协议细节(转) UPnp协议 from wikipedia 考察智力zz JScollPane以及JPanel相关 bmp文件格式 Java媒体框架(JMF),个人很欣赏.... 常用颜色对照表 YUV/YIQ色彩空间的转换 关于Swing实现透明窗体的。我也很喜欢,收藏! java中的数据库程序应用 A*以及迭代加深的A*算法(IDA*) 我的兄弟们之袋鼠篇 深度优先状态搜索法 我的兄弟们之温J篇 java中的图象处理技术基础 经典搜索算实现之一,广度优先.
java中对图象文件的处理(读写以及转换)
空空色色 · 2007-04-24 · via 博客园 - 空空色色

方法一:
(利用imageio类的读写函数)
import javax.imageio.ImageIO;
import java.io.File;
import java.io.IOException;
import java.awt.image.BufferedImage;

public class ChangeImageStyle {

  public static void main(String args[]) throws IOException{
 
    File inputFile = new File("test.bmp");
    BufferedImage input = ImageIO.read(inputFile);

    //转换为gif格式的图片
    File outputFile = new File("test.gif");
    ImageIO.write(input, "GIF", outputFile);

    //转换为jpg格式的图片  
    outputFile = new File("test.jpg");
    ImageIO.write(input, "JPG", outputFile);

    //转换为png格式的图片
    outputFile = new File("test.png");
    ImageIO.write(input, "PNG", outputFile);
  }
}

方法二:
如果你已经把某个文件读入,并存为了Image类的一个实例.
转变方法如下:
其中:image为Image类的一个实例
try{
BufferedImage bi = new BufferedImage(image.getWidth(null), image.getHeight(null),BufferedImage.TYPE_INT_RGB);
Graphics2D biContext = bi.createGraphics();
biContext.drawImage(image, 0, 0, null);
FileOutputStream out=new FileOutputStream("./a1.jpeg");                    
JPEGImageEncoder encoder=JPEGCodec.createJPEGEncoder(out);                    
JPEGEncodeParam param=encoder.getDefaultJPEGEncodeParam(bi);                     
param.setQuality(1.0f,false);
encoder.setJPEGEncodeParam(param);
encoder.encode(bi);
out.flush();
 out.close();
 }catch(Exception EE)
   {
  System.out.println(EE);
   }

方法三:
也就是最笨的方法,弄清楚文件格式,一个字节一个字节的向文件写内容..

总结:最好使用BUFFEREDIMAGE类,免得多了那么多麻烦........