How to traverse pixels in Monochrome Bitmap (pf1bit)

Posted on 1999-01-14
Medium Priority
Last Modified: 2008-03-17
     Basically I want to traverse each pixel in a monochrome bitmap. I tried using PByteArray (for Scanline..) and to loop through the bitmap I've also given Bitmap.Width - 8.
But this method is not working. In Short I want to traverse each pixel, get color info for that pixel and do some calculations based on it,
Please Help me out.
Regards, Jagan
Question by:rjagan
LVL 20

Expert Comment

ID: 1356560
Hi Jagan,

you can either use the ScanLine property. Perhaps the following example from the delphi help file will help you with that...

The problem with this ScanLine property is that you have to bother with things like color depth.
So the example below works only with 256 color bitmaps.

procedure TForm1.Button1Click(Sender: TObject);

// Zeichnung direkt in das BitMap-Objekt ausgeben
  x,y : integer;
  BitMap : TBitMap;
  P : PByteArray;
  BitMap := TBitMap.create;
    for y := 0 to BitMap.height -1 do
      P := BitMap.ScanLine[y];
      for x := 0 to BitMap.width -1 do
        P[x] := y;

Or you could use the bitmap.canvas.pixels property, which is easier to use, but much much slower...

Regards, Madshi.

Accepted Solution

DOsinga earned 120 total points
ID: 1356561
You might also have a try with the WinApi GetDIBits functions. This will allow you to copy the pixels of the bitmap in a format of your choice, to be specified in a passed TBitmapInfo.
LVL 10

Expert Comment

ID: 1356562
YOu go pixel by pixel through the bitmap in order to get eac pixel and do some calculations top it...

for y := 0 to Bitmap.Height do
  for x := 0 to Bitmap.Width do
    bitmap.canvas.pixels[x, y] := bitmap.canvas.pixels[x, y] xor $fafafafa;


Author Comment

ID: 1356563
Thanks a lot for your consideration

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
The video provides a quick and easy steps to migrate MBOX file to well known Outlook PST and Office 365. Besides this, it also supports and migrates more than 20 email clients of MBOX which include AppleMail, Opera, Thunderbird and SeaMonkey effortl…
When you have multiple client accounts to manage, it often feels like there aren’t enough hours in the day. With too many applications to juggle, you can’t focus on your clients, much less your growing to-do list. But that doesn’t have to be the cas…

587 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question