Solved

How to traverse pixels in Monochrome Bitmap (pf1bit)

Posted on 1999-01-14
4
1,276 Views
Last Modified: 2008-03-17
Sir,
     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
0
Comment
Question by:rjagan
4 Comments
 
LVL 20

Expert Comment

by:Madshi
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
var
  x,y : integer;
  BitMap : TBitMap;
  P : PByteArray;
begin
  BitMap := TBitMap.create;
  try
    BitMap.LoadFromFile('..\Images\Splash\256color\factory.bmp');
    for y := 0 to BitMap.height -1 do
    begin
      P := BitMap.ScanLine[y];
      for x := 0 to BitMap.width -1 do
        P[x] := y;
    end;
  canvas.draw(0,0,BitMap);
  finally
    BitMap.free;
  end;
end;

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

Regards, Madshi.
0
 

Accepted Solution

by:
DOsinga earned 30 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.
0
 
LVL 10

Expert Comment

by:viktornet
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;

-Viktor
--Ivanov
0
 

Author Comment

by:rjagan
ID: 1356563
Thanks a lot for your consideration
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

770 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