🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #16872

Re: pf1Bit

#16872
From: Damon Chandler (TeamB)
Date: Wed, 23 Apr 2003 06:19
35 lines
1772 bytes
Hi Vinko,
> How to read bitmap pixels values, if bitmap color depth is only 1 
> bit (black & white)?

You can use the TBitmap::ScanLine property (BCB3+) along with the following
function to read a bit (pixel) of each byte (8 pixels)...

inline bool get_bit(
   unsigned char const& byte_var,
   unsigned char n // zero-based, from left
  )
{
  return (byte_var << n) & 128;
}

Here's a brief example...

  Graphics::TBitmap& Bitmap = *Image1->Picture->Bitmap;
  SIZE const SBmp = {Bitmap.Width, Bitmap.Height};

  for (int y = 0; y < SBmp.cy; ++y)
  {
    unsigned char* pRow =
      static_cast<unsigned char*>(Bitmap.ScanLine[y]);
    for (int x = 0; x < SBmp.cx; ++x)
    {
      bool const is_set = get_bit(pRow[x], N); // define N b/n [0, 7]
      // ...
    }
  }

HTH,
-- 
Damon (TeamB)
BCBCAQ--http://bcbcaq.bytamin-c.com
Technical Details
Message-ID: <3EA63057.3248E06@cornell.edu>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!news.maxwell.syr.edu!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail
References: <3ea57e72@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,65f0c0461351ae3c
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-04-22 23:21:12 PST
Message-ID: <3EA63057.3248E06@cornell.edu>
Date: Wed, 23 Apr 2003 02:19:03 -0400
From: "Damon Chandler (TeamB)" <dmc27@cornell.edu>
X-Mailer: Mozilla 4.8 [en] (Windows NT 5.0; U)
X-Accept-Language: en
MIME-Version: 1.0
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Re: pf1Bit
References: <3ea57e72@newsgroups.borland.com>
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 24.92.234.87
X-Trace: newsgroups.borland.com 1051078670 24.92.234.87 (22 Apr 2003 23:17:50 -0700)
Lines: 35
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!news.maxwell.syr.edu!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail