Recent

Author Topic: Searching for Bitmap.Pixels  (Read 3120 times)

Systrex

  • Newbie
  • Posts: 1
Searching for Bitmap.Pixels
« on: December 07, 2016, 10:22:29 pm »
Hey,

In Delphi I could create a TBitmap, use LoadFromFile and then read the pixels with Bitmap.Canvas.Pixel. How can I do that in lazarus because I cant use TBitmap.create LoadFromFile etc.

Thanks in advance

lainz

  • Hero Member
  • *****
  • Posts: 4460
    • https://lainz.github.io/
Re: Searching for Bitmap.Pixels
« Reply #1 on: December 07, 2016, 11:10:49 pm »
You can use TBGRABitmap, and you can load a bitmap and access pixels with it.
http://wiki.freepascal.org/BGRABitmap_tutorial

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: Searching for Bitmap.Pixels
« Reply #2 on: December 07, 2016, 11:27:52 pm »
It should work like in Delphi:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.   bmp: TBitmap;
  4.   i, j: Integer;
  5.   counter: Integer;
  6. begin
  7.   bmp := TBitmap.Create;
  8.   try
  9.     bmp.LoadFromFile(name_of_your_bitmap_file);
  10.     counter := 0;
  11.     for j := 0 to bmp.Height-1 do
  12.       for i := 0 to bmp.Width - 1 do
  13.         if bmp.Canvas.Pixels[i,j] = clSilver then inc(Counter);
  14.     ShowMessage(IntToStr(counter) + ' pixels in color clSilver detected');
  15.   finally
  16.     bmp.Free;
  17.   end;
  18. end;  

lainz

  • Hero Member
  • *****
  • Posts: 4460
    • https://lainz.github.io/
Re: Searching for Bitmap.Pixels
« Reply #3 on: December 08, 2016, 12:49:25 am »
Nice wp! Im used to work with alpha in bgrabitmap that I forget to use the bitmap that comes with the lcl.

 

TinyPortal © 2005-2018