Solved

How to traverse pixels in Monochrome Bitmap (pf1bit)

Posted on 1999-01-14
4
1,282 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi Seattle: Project Options : Version info for all platforms, all releases? 2 115
Delphi Form ownership 4 127
Working with hours 3 74
Convert MS Word document to a PDF file 9 115
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

726 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