图片格式判断

可以根据图片中取出的byte[]判断图片格式

   byte b[]=new byte[256];
   stream.read(b,0,255);
   System.out.println("******bytes******");
   for(int i=0;i<b.length;i++){
    System.out.print(Integer.toHexString(b[i]&0x0ff)+" ");
   }
   System.out.println();
   System.out.println("******ascii******");
   System.out.println(new String(b));

 

bmp:
42 4d
BM (2bytes)

jpeg:
ff d8

gif:
47 49 46
GIF (3bytes)

png:
89 50 4E 47

猜你喜欢

转载自guoqibiao.iteye.com/blog/1779603