java读图片

来源:百度知道 编辑:UC知道 时间:2024/06/04 10:27:15
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class Test
{

/**
*
*/
public static void main(String[] args) {
byte[] image = new byte[1024];
try {
FileInputStream fileInputStream = new FileInputStream(new File("f:/black.jpg"));
fileInputStream.read(image);
System.out.println(image.length);
FileOutputStream fileOutputStream = new FileOutputStream(new File("f:/xiao.jpg"));

fileOutputStream.write(image);
fileOutputStream.flush();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
}

谁能看看我这写得有错吗?为什么读不到文件?谢谢了
我上面写得只能读文件,不能读图片是为什么

byte[] image = new byte[1024*10];
FileInputStream fileInputStream = new FileInputStream(new File("f:/black.jpg"));
FileOutputStream fileOutputStream = new FileOutputStream(new File("f:/xiao.jpg"));
int i =fileInputStream.read(image);
while(i!=-1)
{
fileOutputStream.write(image,0,i);
fileInputStream.read(image);
}
fileOutputStream .flush();
fileInputStream.close();

这是我上课的时候用JAVA编的一段程序,图片你自己找。用applet来读图片,都差不多,主要是看读图的方法。效果还不错哦。
你如果将这个程序理解了,就可以看到自己程序的问题所在。

import java.awt.*;
import java.applet.*;
import java.awt.image.ImageObserver;
import java.net.URL;

//用Applet显示图片

public class ShowImageApplet extends Applet implements Runnable{
Image[] images; //Applet的Image对象
int xpoint=10; //显示图片的X坐标
int ypoint=10; //显示图片的Y坐标
Thread thread; //图片切换的线程
int currentImage; //当前显示的图片号

public void init(){
set