X-Received: by 10.224.36.66 with SMTP id s2mr7680210qad.6.1367256050258; Mon, 29 Apr 2013 10:20:50 -0700 (PDT) X-Received: by 10.50.196.227 with SMTP id ip3mr375676igc.10.1367256050217; Mon, 29 Apr 2013 10:20:50 -0700 (PDT) Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!s14no833509qam.0!news-out.google.com!ef9ni28916qab.0!nntp.google.com!s14no847391qam.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.python Date: Mon, 29 Apr 2013 10:20:49 -0700 (PDT) Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=114.218.8.106; posting-account=YNiTnAoAAACsQcku3BuAy8Lv9lS0qShZ NNTP-Posting-Host: 114.218.8.106 User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Can read in the BMP data correctly ,but the size is not right? From: Jimmie He Injection-Date: Mon, 29 Apr 2013 17:20:50 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Xref: csiph.com comp.lang.python:44509 I'm trying to read in the BMP data by the the code below,and I'm check t= he data array with WINHEX,and it is correct,but which confuse me is why the= size is 0x180,but the actual picture should be 48*48 =3D 0x120 bytes becau= se I use 1-bit BMP not the 24bit BMP,could any one give some hints? ---------------------------------------------------------------------------= ----- __Head_Info =3D [ [ 'Type' ,0 , 2],#BM [ 'FSize' ,2 , 4],#File Size [ 'Reserved' ,6 , 4],#0x00000000 [ 'OffBits' ,10 , 4],#Offset of Image [ 'SSize' ,14 , 4],# 40 [ 'Width' ,18 , 4],#Width [ 'Height' ,22 , 4],#Hight [ 'Planes' ,26 , 2],#1 [ 'BitCount' ,28 , 2],#{1,2,4,8,24} [ 'Compress' ,30 , 4],#0 [ 'SizeImage' ,34 , 4],#Bytes Per Line [ 'XPM' ,38 , 4],#2835 [ 'YPM' ,42 , 4],#2835 [ 'ClrUsed' ,46 , 4],#0 [ 'ClrImportant' ,50 , 4]#0 ] _Type =3D0; _FSize =3D1; _Reserved =3D2; _OffBits =3D3; _SSize =3D4; _Width =3D5; _Height =3D6; _Planes =3D7; _BitCount =3D8; _Compress =3D9; _SizeImage =3D10; _XPM =3D11; _YPM =3D12; _ClrUsed =3D13; _ClrImportant =3D14; def __getInt( b, idx): return binToInt(b,__Head_Info[idx][1],__Head_Info[idx][2]) def saveMatrixtoASC(bmpfilename,ascfilename): try: handle1=3Dopen( bmpfilename ,"rb") raw =3D bytearray(handle1.read( )) handle1.close except Exception as E: return "error:"+ str(E),"" =20 datastart=3D__getInt(raw, _OffBits) datasize =3D__getInt(raw, _SizeImage) print ('Image Offset =3D 0x%X'%datastart) print ('Image Size =3D 0x%X'%datasize) handle2=3Dopen( ascfilename ,"w") for i in range(0,datasize): handle2.write('0x%02X,'%raw[datastart+i]) if (i+1) % 16 =3D=3D 0 : handle2.write("\n") handle2.close