java - Reading BITMAPFILEHEADER and BITMAPINFOHEADER from a BitMap -


i converting c++ win32 app java (in linux) need read bitmapfileheader , bitmapinfoheader of bitmap , how ? find jna (java native access) library specialized windows (i think). has idea ?

after searching @ web decide implement these structs self , read bitmap file byte array , parse them class data members, here code

public class bitmapfileheader {  char[] bftype; int bfsize; short bfreserved1; short bfreserved2; int bfoffbits;  private bitmapfileheader() {  }  public static bitmapfileheader readfromimage(byte[] image) {      bitmapfileheader bitmap = new bitmapfileheader();      bitmap.bftype = new char[2];     int index = 0;     bitmap.bftype[0] = (char) image[index++];     bitmap.bftype[1] = (char) image[index++];      bitmap.bfsize = (image[index + 3] & 0xff) << 24 | (image[index + 2] & 0xff) << 16 | (image[index + 1] & 0xff) << 8             | (image[index + 0] & 0xff);     index += 4;      bitmap.bfreserved1 = (short) (((image[index + 1] & 0xff) << 8) | (image[index + 0] & 0xff));     index += 2;      bitmap.bfreserved2 = (short) (((image[index + 1] & 0xff) << 8) | (image[index + 0] & 0xff));     index += 2;      bitmap.bfoffbits = (image[index + 3] & 0xff) << 24 | (image[index + 2] & 0xff) << 16 | (image[index + 1] & 0xff) << 8             | (image[index + 0] & 0xff);      return bitmap;  }  }  public class bitmapinfoheader {  int bisize; long biwidth; long biheight; short biplanes; short bibitcount; int bicompression; int bisizeimage; long bixpelspermeter; long biypelspermeter; int biclrused; int biclrimportant;  private bitmapinfoheader() {  }  public static bitmapinfoheader readfromimage(byte[] image) {      bitmapinfoheader bitmap = new bitmapinfoheader();     // littleendian order ...     int index = 14;      bitmap.bisize = (image[index + 3] & 0xff) << 24 | (image[index + 2] & 0xff) << 16 | (image[index + 1] & 0xff) << 8             | (image[index + 0] & 0xff);     index += 4;      bitmap.biwidth = ((image[index + 3] & 0xff) << 24) | (image[index + 2] & 0xff) << 16 | (image[index + 1] & 0xff) << 8             | (image[index + 0] & 0xff);     index += 4;      bitmap.biheight = (image[index + 3] & 0xff) << 24 | (image[index + 2] & 0xff) << 16 | (image[index + 1] & 0xff) << 8             | (image[index + 0] & 0xff);     index += 4;      bitmap.biplanes = (short) (((image[index + 1] & 0xff) << 8) | (image[index + 0] & 0xff));     index += 2;      bitmap.bibitcount = (short) (((image[index + 1] & 0xff) << 8) | (image[index + 0] & 0xff));     index += 2;      bitmap.bicompression = (image[index + 3] & 0xff) << 24 | (image[index + 2] & 0xff) << 16 | (image[index + 1] & 0xff) << 8             | (image[index + 0] & 0xff);     index += 4;      bitmap.bisizeimage = (image[index + 3] & 0xff) << 24 | (image[index + 2] & 0xff) << 16 | (image[index + 1] & 0xff) << 8             | (image[index + 0] & 0xff);     index += 4;      bitmap.bixpelspermeter =     // bytebuffer.wrap(image, index, index +     // 4).order(byteorder.little_endian).getlong();     (int) (image[index + 3] & 0xff) << 24 | (image[index + 2] & 0xff) << 16 | (image[index + 1] & 0xff) << 8 | (image[index + 0] & 0xff);     index += 4;      bitmap.biypelspermeter =              //bytebuffer.wrap(image, index, index + 4).order(byteorder.little_endian).getlong();     (int) (image[index + 3] & 0xff) << 24 | (image[index + 2] & 0xff) << 16 | (image[index + 1] & 0xff) << 8 | (image[index + 0] & 0xff);     index += 4;      bitmap.biclrused = (image[index + 3] & 0xff) << 24 | (image[index + 2] & 0xff) << 16 | (image[index + 1] & 0xff) << 8             | (image[index + 0] & 0xff);     index += 4;      bitmap.biclrimportant = (image[index + 3] & 0xff) << 24 | (image[index + 2] & 0xff) << 16 | (image[index + 1] & 0xff) << 8             | (image[index + 0] & 0xff);     index += 4;      index += 10;     return bitmap;  }  } 

Comments