Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subject:not': 0.03; '"""': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; '384': 0.16; 'confuse': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'exception': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'header:User-Agent:1': 0.23; 'bytes': 0.24; 'header:X-Complaints-To:1': 0.27; 'array': 0.29; "i'm": 0.30; 'code': 0.31; 'url:wiki': 0.31; 'occurs': 0.31; 'subject:size': 0.31; 'url:wikipedia': 0.31; 'file': 0.32; 'raw': 0.33; 'actual': 0.34; 'subject:the': 0.34; 'something': 0.35; 'subject:data': 0.36; 'subject:?': 0.36; 'url:org': 0.36; 'should': 0.36; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'according': 0.40; 'read': 0.60; 'subject:Can': 0.60; 'subject:read': 0.84; 'picture': 0.97 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: Can read in the BMP data correctly ,but the size is not right? Date: Mon, 29 Apr 2013 19:57:07 +0200 Organization: None References: Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p5084aec3.dip0.t-ipconnect.de User-Agent: KNode/4.7.3 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 29 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1367258242 news.xs4all.nl 15994 [2001:888:2000:d::a6]:43166 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:44513 Jimmie He wrote: > I'm trying to read in the BMP data by the the code below,and I'm check > the 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 = 0x120 > bytes because I use 1-bit BMP not the 24bit BMP,could any one give some > hints? According to wikipedia """ The size of each row is rounded up to a multiple of 4 bytes [...] """ So 48/8 == 6 will be rounded to 8, and 8*48 == 384 == 0x180. > handle1=open( bmpfilename ,"rb") > raw = bytearray(handle1.read( )) > handle1.close To actually do something the last line should be handle1.close(). I recommend with open(bmpfilename ,"rb") as handle1: raw = bytearray(handle1.read()) instead which has the additional advantage that the file will be closed if an exception occurs in the with-suite.