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

推荐订阅源

B
Blog RSS Feed
D
Darknet – Hacking Tools, Hacker News & Cyber Security
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
G
Google Developers Blog
MyScale Blog
MyScale Blog
Google DeepMind News
Google DeepMind News
J
Java Code Geeks
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
C
Check Point Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
P
Proofpoint News Feed
D
Docker
Jina AI
Jina AI
博客园 - 三生石上(FineUI控件)
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Help Net Security
Help Net Security
Google DeepMind News
Google DeepMind News
L
LINUX DO - 最新话题
T
Tailwind CSS Blog
N
Netflix TechBlog - Medium
Forbes - Security
Forbes - Security
MongoDB | Blog
MongoDB | Blog
Attack and Defense Labs
Attack and Defense Labs
Webroot Blog
Webroot Blog
A
About on SuperTechFans
Schneier on Security
Schneier on Security
Hacker News - Newest:
Hacker News - Newest: "LLM"
Microsoft Azure Blog
Microsoft Azure Blog
F
Fortinet All Blogs
IT之家
IT之家
The Last Watchdog
The Last Watchdog
腾讯CDC
Microsoft Security Blog
Microsoft Security Blog
Project Zero
Project Zero
B
Blog
Recorded Future
Recorded Future
博客园_首页
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
S
SegmentFault 最新的问题
Security Archives - TechRepublic
Security Archives - TechRepublic
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
H
Hacker News: Front Page
T
Threatpost
H
Heimdal Security Blog
Cloudbric
Cloudbric
Google Online Security Blog
Google Online Security Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
V2EX
云风的 BLOG
云风的 BLOG
V
Visual Studio Blog

博客园 - 空空色色

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