社区
Java SE
帖子详情
java如何转换图片格式,高分求助,急!!
lionheartliu
2004-12-28 10:29:16
小弟是一名菜鸟,现在要转换图片格式,如:把jpg转换成bmp、把tif转换成jpg等,那位大虾有通用的转换图片格式的程序或好的方法,请不吝赐教,如有程序请详细贴出来,试验成功后一定高分相送!急!
...全文
406
7
打赏
收藏
java如何转换图片格式,高分求助,急!!
小弟是一名菜鸟,现在要转换图片格式,如:把jpg转换成bmp、把tif转换成jpg等,那位大虾有通用的转换图片格式的程序或好的方法,请不吝赐教,如有程序请详细贴出来,试验成功后一定高分相送!急!
复制链接
扫一扫
分享
转发到动态
举报
AI
作业
写回复
配置赞助广告
用AI写文章
7 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
lionheartliu
2004-12-29
打赏
举报
回复
dreamno,你好,我看了你的程序,给了我一些启发,但是执行你的程序后,总是显示“Invalid input file format”,我选择的是tif格式的图片文件,要转换成jpg的格式,我选择bmp的都不行,请问为什么,
dreamno
2004-12-29
打赏
举报
回复
需要jai_codec.jar,jai_core.jar这两个包。
可以在:
http://java.sun.com/products/java-media/jai/downloads/download-iio.html
下在到.如果不行的话。你给我留个
mail我给你发过去。
dreamno
2004-12-29
打赏
举报
回复
public static boolean convert(String source,String target){
try {
RenderedOp rop = JAI.create("fileload", source);
OutputStream outStream = new FileOutputStream(target);
BMPEncodeParam param = new BMPEncodeParam();
ImageEncoder imageEncoder = ImageCodec.createImageEncoder("BMP",
outStream,
param);
imageEncoder.encode(rop);
outStream.close();
}
catch(Exception ex){
return false;
}
return true;
}
lionheartliu
2004-12-28
打赏
举报
回复
没人回答吗?自己顶一下,希望高手出招!
dreamno
2004-12-28
打赏
举报
回复
package com.liming.applet;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import javax.swing.*;
import java.io.*;
import java.net.*;
import javax.imageio.*;
public class Converting
extends JFrame {
JLabel promptLabel;
JTextField prompt;
JButton promptButton;
JFileChooser fileChooser;
JComboBox comboBox;
JButton saveButton;
public Converting() {
super("Image Conversion");
setDefaultCloseOperation(EXIT_ON_CLOSE);
Container contentPane = getContentPane();
JPanel inputPanel = new JPanel();
promptLabel = new JLabel("Filename:");
inputPanel.add(promptLabel);
prompt = new JTextField(20);
inputPanel.add(prompt);
promptButton = new JButton("Browse");
inputPanel.add(promptButton);
contentPane.add(inputPanel, BorderLayout.NORTH);
fileChooser = new JFileChooser();
promptButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int returnValue = fileChooser.showOpenDialog(null);
if (returnValue == JFileChooser.APPROVE_OPTION) {
File selectedFile = fileChooser.getSelectedFile();
if (selectedFile != null) {
prompt.setText(selectedFile.getAbsolutePath());
}
}
}
});
JPanel outputPanel = new JPanel();
String writerFormats[] = ImageIO.getWriterFormatNames();
ComboBoxModel comboBoxModel = new DefaultComboBoxModel(writerFormats);
comboBox = new JComboBox(comboBoxModel);
outputPanel.add(comboBox);
saveButton = new JButton("Save");
outputPanel.add(saveButton);
saveButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
String name = prompt.getText();
File file = new File(name);
if (file.exists()) {
BufferedImage image = ImageIO.read(file.toURL());
if (image == null) {
System.err.println(
"Invalid input file format");
}
else {
String selection = (String
) comboBox.getSelectedItem();
String outputFilename = name + "." + selection;
File outputFile = new File(outputFilename);
boolean found = ImageIO.write(image, selection,
outputFile);
if (found) {
JDialog window = new JDialog();
Container windowContent = window.getContentPane();
BufferedImage newImage = ImageIO.read(
outputFile);
JLabel label = new JLabel(new ImageIcon(
newImage));
JScrollPane pane = new JScrollPane(label);
windowContent.add(pane, BorderLayout.CENTER);
window.setSize(300, 300);
window
.show();
}
else {
System.err.println("Error saving");
}
}
}
else {
System.err.println("Bad filename");
}
}
catch (MalformedURLException mur) {
System.err.println("Bad filename");
}
catch (IOException ioe) {
System.err.println("Error reading file");
}
}
});
contentPane.add(outputPanel, BorderLayout.SOUTH);
}
public static void main(String args[]) {
JFrame frame = new Converting();
frame.pack();
frame.show();
}
}
dreamno
2004-12-28
打赏
举报
回复
BufferedImage
dreamno
2004-12-28
打赏
举报
回复
jdk里有专门的api你可以找找.忘记是啥了。好象是...Stream.class
webmagic采集CSDN的
Java
_WebDevelop页面
, 请问如何设置SVN的权限, 腾讯视频 根据腾讯视频的vid获取视频信息, 求教activiti关于普通表单的理解~, mmGrid提交数据到struts action, 菜鸟
求助
!对接多个银行这样设计合不合理呢?, 这是什么错??Resource Path...
vb/vb.net开发精粹(2)
关于EXCEL
转换
成ACCESS库 关于vb生成exe后出现的问题,
急
!!!! 一道不知拿不定主意的小题 是不是需要刷新一下窗口? vb 连接sql2000 数据库 超慢的问题~ uridownloadtofile 函数问题 VB6.0如何调用打印纸格
vb/vb.net原创文章精粹(2)
[url=http://www.vbbaike.com/show.asp?id=101290]关于EXCEL
转换
成ACCESS库[/url] [url=http://www.vbbaike.com/show.asp?id=101289]关于vb生成exe后出现的问题,
急
!!!![/url] [url=...
【附源码】网上人才招聘系统(源码+数据库+毕业论文齐全)
java
开发ssm框架,可做毕业设计
网上人才招聘系统,主要采用的是
JAVA
语言来进行开发,采用SSM框架,JSP技术,对于各个模块设计制作有一定的安全性;数据库方面主要采用的是MySQL来进行开发,其特点是稳定性好,数据库存储容量大,处理能力快等优势...
【附源码】自习室预约管理系统(源码+数据库+毕业论文齐全)
java
开发ssm框架,可做毕业设计
网站的搭建与开发采用了先进的
java
进行编写,JSP技术,使用了SSM框架。该系统从两个对象:由管理员和学生来对系统进行设计构建。主要功能包括:个人信息修改,对自习室类型、自习室、座位预订、取消预订等功能进行...
Java SE
62,635
社区成员
307,269
社区内容
发帖
与我相关
我的任务
Java SE
Java 2 Standard Edition
复制链接
扫一扫
分享
社区描述
Java 2 Standard Edition
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章