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

推荐订阅源

Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Microsoft Azure Blog
Microsoft Azure Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Webroot Blog
Webroot Blog
腾讯CDC
The Last Watchdog
The Last Watchdog
博客园 - 司徒正美
H
Hacker News: Front Page
I
InfoQ
A
Arctic Wolf
H
Hackread – Cybersecurity News, Data Breaches, AI and More
H
Heimdal Security Blog
L
LINUX DO - 最新话题
T
Threat Research - Cisco Blogs
宝玉的分享
宝玉的分享
Last Week in AI
Last Week in AI
Security Latest
Security Latest
D
DataBreaches.Net
C
Check Point Blog
J
Java Code Geeks
www.infosecurity-magazine.com
www.infosecurity-magazine.com
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Attack and Defense Labs
Attack and Defense Labs
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
L
Lohrmann on Cybersecurity
雷峰网
雷峰网
Vercel News
Vercel News
WordPress大学
WordPress大学
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Spread Privacy
Spread Privacy
Forbes - Security
Forbes - Security
阮一峰的网络日志
阮一峰的网络日志
Hacker News: Ask HN
Hacker News: Ask HN
大猫的无限游戏
大猫的无限游戏
I
Intezer
N
News and Events Feed by Topic
小众软件
小众软件
B
Blog RSS Feed
Help Net Security
Help Net Security
Google DeepMind News
Google DeepMind News
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - 三生石上(FineUI控件)
S
Security @ Cisco Blogs
美团技术团队
Recent Announcements
Recent Announcements
Martin Fowler
Martin Fowler
Engineering at Meta
Engineering at Meta
The GitHub Blog
The GitHub Blog
MyScale Blog
MyScale Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main

博客园 - 空空色色

转一篇,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类,免得多了那么多麻烦........