Solved

How to traverse pixels in Monochrome Bitmap (pf1bit)

Posted on 1999-01-14
4
1,269 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks a lot for your consideration
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

744 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now