1 Public voidGetbmpimage (String Source)throwsException {2 3Clearndata ();//Clear Data Save area4FileInputStream fs =NULL;5 6 Try {7FS =NewFileInputStream (source);8 intBflen = 14;9 byteBf[] =New byte[Bflen];TenFs.read (BF, 0, Bflen);//read 14-byte BMP file header One intBilen = 40; A byteBi[] =New byte[Bilen]; -Fs.read (BI, 0, Bilen);//read 40-byte BMP information header - //Source Graph Width theNwidth = (((int) bi[7] & 0xff) << 24) -| (((int) bi[6] & 0xff) << 16) -| (((int) bi[5] & 0xff) << 8) | (int) Bi[4] & 0xFF; - //Source Graph Height +Nheight = (((int) bi[11] & 0xff) << 24) -| (((int) bi[10] & 0xff) << 16) +| (((int) bi[9] & 0xff) << 8) | (int) Bi[8] & 0xFF; A //Number of digits atNbitcount = (((int) bi[15] & 0xff) << 8) | (int) bi[14] & 0xFF; - //Source Map Size - intNsizeimage = (((int) bi[23] & 0xff) << 24) -| (((int) bi[22] & 0xff) << 16) -| (((int) bi[21] & 0xff) << 8) | (int) bi[20] & 0xFF; - //parsing of 24-bit BMP in if(Nbitcount = = 24){ - intNpad = (nsizeimage/nheight)-nwidth * 3; toNdata =New int[Nheight *nwidth]; +nb=New int[Nheight *nwidth]; -Nr=New int[Nheight *nwidth]; theng=New int[Nheight *nwidth]; * byteBrgb[] =New byte[(nwidth + npad) * 3 *nheight]; $Fs.read (Brgb, 0, (nwidth + npad) * 3 *nheight);Panax Notoginseng intNIndex = 0; - for(intj = 0; J < nheight; J + +){ the for(inti = 0; i < nwidth; i++) { +Ndata[nwidth * (NHEIGHT-J-1) + i] = (255 & 0xff) << 24 A| (((int) Brgb[nindex + 2] & 0xff) << 16) the| (((int) Brgb[nindex + 1] & 0xff) << 8) +| (int) Brgb[nindex] & 0xFF; -Nb[nwidth * (NHEIGHT-J-1) + i]= (int) brgb[nindex]& 0xFF; $Ng[nwidth * (NHEIGHT-J-1) + i]= (int) brgb[nindex+1]& 0xFF; $Nr[nwidth * (NHEIGHT-J-1) + i]= (int) brgb[nindex+2]& 0xFF; -NIndex + = 3; - } theNIndex + =Npad; - }Wuyi //Toolkit kit = Toolkit.getdefaulttoolkit (); the //image = Kit.createimage (new MemoryImageSource (nwidth, nheight, - //ndata, 0, nwidth)); Wu /* - //reading of debug data About FileWriter fw = new FileWriter ("C:\\Documents and Settings\\administrator\\my Documents\\ndataraw.txt" );//Create a new file $ PrintWriter out = new PrintWriter (FW); - for (int j=0;j<nheight;j++) { - for (int i=0;i<nwidth;i++) { - Out.print ((65536*256+ndata[nwidth * (NHEIGHT-J-1) + i]) + "_" A +nr[nwidth * (NHEIGHT-J-1) + i]+ "_" + +ng[nwidth * (NHEIGHT-J-1) + i]+ "_" the +nb[nwidth * (NHEIGHT-J-1) + i]+ ""); - $ } the out.println (""); the } the out.close (); the */ - } in } the Catch(Exception e) { the e.printstacktrace (); About Throw NewException (e); the } the finally { the if(FS! =NULL) { + fs.close (); - } the }Bayi //return image; the}
Read BMP image Data