Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #44513

Re: Can read in the BMP data correctly ,but the size is not right?

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 <python-python-list@m.gmane.org>
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 <aee818ca-e077-4e52-be55-7b8282684ba4@googlegroups.com>
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 <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1159.1367258242.3114.python-list@python.org> (permalink)
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

Show key headers only | View raw


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 <http://en.wikipedia.org/wiki/BMP_file_format>

"""
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.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Can read in the BMP data correctly ,but the size is not right? Jimmie He <jimmie.he@gmail.com> - 2013-04-29 10:20 -0700
  Re: Can read in the BMP data correctly ,but the size is not right? Chris Angelico <rosuav@gmail.com> - 2013-04-30 03:53 +1000
  Re: Can read in the BMP data correctly ,but the size is not right? Peter Otten <__peter__@web.de> - 2013-04-29 19:57 +0200
    Re: Can read in the BMP data correctly ,but the size is not right? Jimmie He <jimmie.he@gmail.com> - 2013-04-30 06:09 -0700
    Re: Can read in the BMP data correctly ,but the size is not right? Jimmie He <jimmie.he@gmail.com> - 2013-05-04 03:26 -0700
  Re: Can read in the BMP data correctly ,but the size is not right? MRAB <python@mrabarnett.plus.com> - 2013-04-29 19:10 +0100
  Re: Can read in the BMP data correctly ,but the size is not right? 88888 Dihedral <dihedral88888@googlemail.com> - 2013-04-29 11:12 -0700

csiph-web