关于java 载入和保存图片的问题
展开全部
JLabel jb = new JLabel();
String icon = "E:/图标/admin_key.gif";
String savePath = "D:/photo";
FileInputStream fis = new FileInputStream(icon);
FileOutputStream fos = new FileOutputStream(savePath+"image.jpg");
byte[] buff = new byte[1024];
int flag = 0;
while ((flag = fis.read(buff, 0, buff.length)) != -1) {
fos.write(buff, 0, flag);
}
fis.close();
fos.close();
jb.setIcon(new ImageIcon(icon));
String icon = "E:/图标/admin_key.gif";
String savePath = "D:/photo";
FileInputStream fis = new FileInputStream(icon);
FileOutputStream fos = new FileOutputStream(savePath+"image.jpg");
byte[] buff = new byte[1024];
int flag = 0;
while ((flag = fis.read(buff, 0, buff.length)) != -1) {
fos.write(buff, 0, flag);
}
fis.close();
fos.close();
jb.setIcon(new ImageIcon(icon));
展开全部
import java.awt.Container;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
/**
* @author Administrator
*
*/
public class ImageSave extends JFrame{
/**
* @param args
*/
public static void main(String[] args) {
new ImageSave();
}
String bmpFile = "c:/temp/temp.bmp";
String savePath = "c:/temp/save.bmp";
public ImageSave(){
super("save bmp");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(500, 160);
setVisible(true);
JLabel jl = new JLabel("hello");
ImageIcon ii = new ImageIcon(bmpFile);
jl.setIcon(ii);
//将组件添加到面板中
Container cn = getContentPane();
cn.add(jl);
try {
FileInputStream in = new FileInputStream(new File(bmpFile));
File file = new File(savePath);
if (!file.exists()) {
file.createNewFile();
}
FileOutputStream outStream = new FileOutputStream(file);
int b;
while((b=in.read())!=-1){
outStream.write(b);
}
} catch (Exception ex) {
}
}
}
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
/**
* @author Administrator
*
*/
public class ImageSave extends JFrame{
/**
* @param args
*/
public static void main(String[] args) {
new ImageSave();
}
String bmpFile = "c:/temp/temp.bmp";
String savePath = "c:/temp/save.bmp";
public ImageSave(){
super("save bmp");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(500, 160);
setVisible(true);
JLabel jl = new JLabel("hello");
ImageIcon ii = new ImageIcon(bmpFile);
jl.setIcon(ii);
//将组件添加到面板中
Container cn = getContentPane();
cn.add(jl);
try {
FileInputStream in = new FileInputStream(new File(bmpFile));
File file = new File(savePath);
if (!file.exists()) {
file.createNewFile();
}
FileOutputStream outStream = new FileOutputStream(file);
int b;
while((b=in.read())!=-1){
outStream.write(b);
}
} catch (Exception ex) {
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询