关于图片加水印的问题,有些疑问,100分得给
//水印处理的包
package james.cmb;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.awt.image.*;
import org.w3c.dom.*;
import com.sun.image.codec.jpeg.*;
import javax.imageio.*;
public class ImgBean_i{
public void ImgBean_i(){
}
public void ImgYin(String Imagename_biao,String ImgName){
try{
File _file = new File(ImgName);
Image src = ImageIO.read(_file);
int wideth=src.getWidth(null);
int height=src.getHeight(null);
BufferedImage image=new BufferedImage(wideth,height,BufferedImage.TYPE_INT_RGB);
Graphics g=image.createGraphics();
g.drawImage(src,0,0,wideth,height,null);
//水印文件
File _filebiao = new File(Imagename_biao);
Image src_biao = ImageIO.read(_filebiao);
int wideth_biao=src_biao.getWidth(null);
int height_biao=src_biao.getHeight(null);
g.drawImage(src_biao,wideth-110,height-110,wideth_biao,height_biao,null);
///
g.dispose();
FileOutputStream out=new FileOutputStream(ImgName);
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
encoder.encode(image);
out.close();
}
catch(Exception e){
System.out.println(e);
}
}
}
//调用的jsp程序
com.pic.ImgBean_i bbb= new com.pic.ImgBean_i();
bbb.ImgYin(path+"/photo/images/shuiyin.gif",path+"/photo/upfile/" + newname);
resin总是报错:can't read input file!!!
为什么啊,各位救救我!
问题点数:100、回复次数:8Top
1 楼cceyjames(千堆雪)回复于 2005-04-04 10:57:03 得分 0
resin为什么总是报错阿:can't read input file!
Top
2 楼zxmzfbdc(也速该把阿秃儿)回复于 2005-04-04 10:59:58 得分 20
确认访问源文件的方法正确吗?最好把所有的exception信息都贴出来,这样才好找问题。Top
3 楼cceyjames(千堆雪)回复于 2005-04-04 11:10:00 得分 0
这个类很多人都用过啊,为什么我这里就不能用呢
resin输出的异常信息是:Javax.imageio.iioexcespotion: can't read input file!
跪求!!!!!!!!!!!!!111Top
4 楼cceyjames(千堆雪)回复于 2005-04-04 11:12:53 得分 0
//调用的jsp程序 (对不起)
james.cmb.ImgBean_i bbb= new com.pic.ImgBean_i();
bbb.ImgYin("/photo/images/shuiyin.gif","/photo/upfile/" + newname);
谁能救救我!!!!Top
5 楼cceyjames(千堆雪)回复于 2005-04-04 11:13:30 得分 0
我考,还是写错了
//调用的jsp程序 (对不起)
james.cmb.ImgBean_i bbb= new james.cmb.ImgBean_i();
bbb.ImgYin("/photo/images/shuiyin.gif","/photo/upfile/" + newname);
谁能救救我!!!!
Top
6 楼javafaq2004(I will survive)回复于 2005-04-05 09:33:26 得分 50
晕菜,给你临时写一个:
import javax.imageio.ImageIO;
import java.io.File;
import java.awt.Component;
import java.awt.MediaTracker;
public class TestImage extends Component{
public static void main(String[] args) throws Exception{
TestImage ti = new TestImage();
Toolkit toolkit = Toolkit.getDefaultToolkit();
Image im = toolkit.getImage("197.jpg");
try {
MediaTracker tracker = new MediaTracker(ti);
tracker.addImage(im, 0);
tracker.waitForID(0);
} catch (Exception e) {
System.out.println(e.getMessage());
}
BufferedImage image = new BufferedImage(im.getWidth(ti), im.getHeight(ti), BufferedImage.TYPE_INT_RGB);
Graphics graphics = image.getGraphics();
graphics.drawImage(im, 0, 0, ti);
graphics.setFont(new Font("Courier New", Font.BOLD, 72));
graphics.drawString("I'l kill you!", 80, 80);
File f = new File("test.jpg");
ImageIO.write(image, "jpg", f);
}
}Top
7 楼F1in2003(无敌超级赛亚人)回复于 2005-04-05 13:23:26 得分 30
你先把_filebiao的路径print 出来,看是不是你那个路径(应该是这个问题是)Top
8 楼cceyjames(千堆雪)回复于 2005-04-06 12:14:10 得分 0
谢谢,已经搞定了!Top




