Thread View: borland.public.cppbuilder.nativeapi
3 messages
3 total messages
Started by Vinko
Tue, 22 Apr 2003 17:39
pf1Bit
Author: Vinko
Date: Tue, 22 Apr 2003 17:39
Date: Tue, 22 Apr 2003 17:39
11 lines
1250 bytes
1250 bytes
Hi! How to read bitmap pixels values, if bitmap color depth is only 1 bit (black & white)? Canvas->Pixels[x][y] can simply read pixel value, but it is too slow. I would like to read pixels with ScanLine method. If bitmap is pf8bit, pf24bit or pf32bit i can do that, but with pf1bit, without luck. I also tryed with bits shifting. THANK YOU, Saso
Re: pf1Bit
Author: Martin Moeller
Date: Tue, 22 Apr 2003 20:22
Date: Tue, 22 Apr 2003 20:22
7 lines
1114 bytes
1114 bytes
"Vinko" <digitalsv@email.si> wrote: > I also tryed with bits shifting. If not by shift, you could try masking and testing the result. Martin
Re: pf1Bit
Author: Damon Chandler (TeamB)
Date: Wed, 23 Apr 2003 06:19
Date: Wed, 23 Apr 2003 06:19
35 lines
1772 bytes
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
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads