下面的方法哪儿错了?
执行out.write(img).报异常:NotSerializableExceptionpublic void writeImg(File file,Image img){
try {
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(file));
out.writeObject(img);
out.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
执行out.write(img).报异常:NotSerializableExceptionpublic void writeImg(File file,Image img){
try {
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(file));
out.writeObject(img);
out.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import java.awt.Image;
Image yourImage = ...
BufferedImage bi = new BufferedImage(yourImage.getWidth(),yourImage.getHeight(), BufferedImage.TYPE_INT_ARGB);
java.awt.Graphics g = bi.getGraphics();
g.drawImage(yourImage, 0, 0, null);
OutputStream output = ...
ImageIO.write(bi, "gif ", output);
java.io.ByteArrayOutputStream output = new java.io.ByteArrayOutputStream();
ImageIO.write(bi, "gif ", output);
byte[] buff = output.toByteArray();
java.io.InputStream is = new java.io.ByteArrayInputStream(buff);
什么意思?