日期:2014-05-20  浏览次数:20743 次

java 读bmp文件
Java code
FILE *fp;
char sk[50];
int col =400;
int row =400;
unsigned char buf[165000];

sprintf(sk,"2.bmp");
  fp=fopen(sk,"r+b");
  if(fp!=NULL){    
       fseek(fp,1078,0);
     for(int i=0;i<col;i++){
         fread(buf+(col-i-1)*row,row,1,fp);
     }

vc的代码读bmp文件到buf中,哪位帮忙下用java实现。 谢了。

------解决方案--------------------
http://blog.csdn.net/chjk1/article/details/1924772
参考
------解决方案--------------------
Java code

File file = new File("e:\\abc.bmp");
        FileInputStream fis = new FileInputStream("e:\\abc.bmp");
        
        byte[] b = new byte[100];
        byte[] fileByte = new byte[(int)file.length()];
        
        int i = -1;
        int index = 0;
        
        while((i = fis.read(b, 0, 100)) != -1)
        {
            for(int j = 0;j < i;j++)
            {
                fileByte[index++] = b[j];
            }
        }
        fis.close();

------解决方案--------------------
public class HelloJava{
public static void main (String[] args){
Image image = null;
try {
// Read from a file
File sourceimage = new File("source.gif"); //source.gif图片要与HelloJava.java同在一目录下
image = ImageIO.read(sourceimage);

// Read from an input stream
InputStream is = new BufferedInputStream(
new FileInputStream("mid.jpg")); //mid.jpg图片要与HelloJava.java同在一目录下
image = ImageIO.read(is);

// Read from a URL
URL url = new URL("http://www.javaworld.com/images/012407-tipsbox.jpg");
image = ImageIO.read(url);
} catch (IOException e) {
}

------解决方案--------------------
google 总是最好的。
------解决方案--------------------
java 5 开始 ImageIO 可以读 BMP 图片。