java jimi开发报错: No source image set.

hardbull 2011-09-03 01:26:31
想将TIF格式的图像转换为JPG,调用了Jimi的函数,程序如下:

public void convertToJPG(String source, String dest, int quality) {
if (source.trim().equals("") || source == null || dest.trim().equals("") || dest == null) {
System.out.println("Error:Not to found the file ");
} else {
dest += ".jpg";
}
try {
JPGOptions options = new JPGOptions();
options.setQuality(quality);
ImageProducer image = Jimi.getImageProducer(source);
JimiWriter writer = Jimi.createJimiWriter(dest);
writer.setSource(image);
writer.setOptions(options);
writer.putImage(dest);
} catch (Exception es) {
System.out.println(es);
}
}

只生成空的JPG图像文件,报错:Error:Not to create a JPG image.com.sun.jimi.core.JimiException: No source image set.
大家是否已到如此问题,请帮忙!
...全文
484 14 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
翰林听海 2013-12-10
  • 打赏
  • 举报
回复
如果你那么想做转换,可以把里面的东西拿出来,因为我在看jimi的代码,错误非常多,很久没有维护了, 只把你想要的拿出来就行啦.
翰林听海 2013-12-10
  • 打赏
  • 举报
回复
jimi包本身的代码都有很多错误,
zebinluo999 2013-05-23
  • 打赏
  • 举报
回复
搞定没有兄弟
hardbull 2012-07-31
  • 打赏
  • 举报
回复
还没搞定
zebinluo999 2012-05-20
  • 打赏
  • 举报
回复
还没搞定啊
hardbull 2012-03-31
  • 打赏
  • 举报
回复
还有没有高手,困扰了很久:
源码:
import com.sun.jimi.core.*;
import java.awt.image.*;
import com.sun.jimi.core.JimiException.*;
import com.sun.jimi.core.options.JPGOptions;
import com.sun.jimi.core.options.FormatOptionSet;
import java.io.File;

public class convertToJPG
{
public void convertToJPG(String source, String dest, int quality) throws JimiException {
if (source.trim().equals("") || source == null || dest.trim().equals("") || dest == null) {
System.out.println("Error:Not to found the file ");
} else {
dest += ".jpg";
}
try {
JPGOptions options = new JPGOptions();
options.setQuality(quality);
ImageProducer image = Jimi.getImageProducer(source);
JimiWriter writer = Jimi.createJimiWriter(dest);
writer.setSource(image);
writer.setOptions(options);
writer.putImage(dest);

} catch (Exception es) {
System.out.println("在原函数中" + es);
}
}
public static void main(String[] args)
{
File files=new File("aa.tif");
convertToJPG jpg=new convertToJPG();

try
{
jpg.convertToJPG(files.getName(),"test",75);
}
catch (Exception es)
{
System.out.println("This error is:"+es);
}

}
}

还是报:在原函数中com.sun.jimi.core.JimiException: No source image set.
路径都是对的呀,并且在路径下确实有此aa.tif图片文件。

跪求高手指导!!!
huntor 2011-09-03
  • 打赏
  • 举报
回复
这就奇怪了。

hardbull 2011-09-03
  • 打赏
  • 举报
回复
就改为:pptc.convertToJPG(filePath, direction + picID, 75); //filePaht="D:\\java_script\\OA\\imageFiles\\593419.TIF" 也不行呀,活见鬼了。
huntor 2011-09-03
  • 打赏
  • 举报
回复
pptc.convertToJPG(file.getName(), direction + picID, 75);

问题应该在这里

new File("/tmp/maven.txt").getName() ; "maven.txt"
new File("/tmp/maven.txt").getPath() ; "/tmp/maven.txt"
hardbull 2011-09-03
  • 打赏
  • 举报
回复
程序是这样的,输入一个图片ID号,从数据库中提取数据保存成.TIF文件并存在D:\java_script\OA\imageFiles\目录下,然后把该.tif图片转成.jpg用于在页面显示。

源代码:
public void GetImgByteById(String picID) throws SQLException, IOException {
FileOutputStream fos = null;
String direction = "D:\\java_script\\OA\\imageFiles\\";
String fileName = picID + ".tif";
String filePath = direction + fileName;
InputStream inStream = null;
byte[] Buffer = new byte[4096];
ResultSet rs = null;
pictureOperate.pictureTypeConvert pptc = new pictureTypeConvert();

try {
databaseConnection dbc = new databaseConnection();
String sqlStr = "select pic_pic from sys_data_pic where pic_id=" + picID;
if (dbc.connection()) {
rs = dbc.selection(sqlStr);
}
if (rs.next()) {
File file = new File(filePath);
if (!file.exists()) {
file.createNewFile();
}
fos = new FileOutputStream(file);
java.sql.Blob blob = rs.getBlob("pic_pic");
inStream = blob.getBinaryStream();
int size = 0;
while ((size = inStream.read(Buffer)) != -1) {
fos.write(Buffer, 0, size);
}
fos.close();
pptc.convertToJPG(file.getName(), direction + picID, 75);

}
} catch (Exception e) {
System.out.println("输入文件错误:" + e.getMessage());
} finally {
//fos.close();
rs.close();
}
}
huntor 2011-09-03
  • 打赏
  • 举报
回复
我使用这个方法将一个png转到 jpeg。
如果source指定的png文件不存在
com.sun.jimi.core.JimiException: No source image set.
at com.sun.jimi.core.JimiWriter.putImage(JimiWriter.java:263)
at com.sun.jimi.core.JimiWriter.putImage(JimiWriter.java:238)
hardbull 2011-09-03
  • 打赏
  • 举报
回复
回复 huntor:文件会存在,因为程序先生成.tif文件,再转换的成.jpg文件。

huntor 2011-09-03
  • 打赏
  • 举报
回复
if((source == null || source.trim().isEmpty()) && (dest ==null || dest.trim().isEmpty()))
huntor 2011-09-03
  • 打赏
  • 举报
回复
你确认 source 指向的文件存在?

62,635

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧