Recent

Author Topic: Does GetPixel work with TBGRABitmap?  (Read 601 times)

user5

  • Sr. Member
  • ****
  • Posts: 273
Does GetPixel work with TBGRABitmap?
« on: December 17, 2019, 10:59:24 am »
    I can't get GetPixel(x,y) to work with TBGRABitmap. The code below keeps coming up with clNone. Can someone show me what I'm doing wrong or show me a simple example of how to use GetPixel with TBGRABitmap? Thanks.

   
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button12Click(Sender: TObject);
  2. var mybitmap:TBitmap;
  3.     bgra:TBGRABitmap;
  4.     tempcolor:TColor;
  5.     tempstr:string;
  6. begin
  7.  
  8.  mybitmap := TBitmap.create;
  9.  mybitmap.width := image1.width;
  10.  mybitmap.height := image1.height;
  11.  mybitmap.assign(image1.picture.bitmap);
  12.  application.processmessages;
  13.  
  14.  bgra := TBGRABitmap.create(mybitmap.width,mybitmap.height);
  15.  bgra.assign(mybitmap);
  16.  
  17.  tempcolor := bgra.GetPixel(30,30);
  18.  tempstr := ColorToString(tempcolor);
  19.  edit1.text := tempstr;
  20.  
  21.  bgra.free;
  22.  mybitmap.free;
  23.  
  24. end;

user5

  • Sr. Member
  • ****
  • Posts: 273
Re: Does GetPixel work with TBGRABitmap?
« Reply #1 on: December 17, 2019, 01:00:02 pm »
    I did some research and testing and found something that works. If anyone is interested the code below works with GetPixel and BGRABitmap. Thanks anyway.

   
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button12Click(Sender: TObject);
  2. var mybitmap:TBitmap;
  3.     bgra:TBGRABitmap;
  4.     tempcolor:TColor;
  5.     tempstr:string;
  6.     c: TBGRAPixel;
  7. begin
  8.  
  9.  mybitmap := TBitmap.create;
  10.  mybitmap.width := image1.width;
  11.  mybitmap.height := image1.height;
  12.  mybitmap.assign(image1.picture.bitmap);
  13.  application.processmessages;
  14.  
  15.  bgra := TBGRABitmap.create(mybitmap.width,mybitmap.height);
  16.  bgra.assign(mybitmap);
  17.  
  18.  c := bgra.GetPixel(30,30);
  19.  tempcolor := BGRAToColor(c);
  20.  
  21.  tempstr := ColorToString(tempcolor);
  22.  edit1.text := tempstr;
  23.  
  24.  bgra.free;
  25.  mybitmap.free;
  26.  
  27. end;

circular

  • Hero Member
  • *****
  • Posts: 3440
    • Personal webpage
Re: Does GetPixel work with TBGRABitmap?
« Reply #2 on: December 19, 2019, 04:53:40 pm »
You can try something like
bgra.GetPixel(30,30).ToColor
Conscience is the debugger of the mind

winni

  • Hero Member
  • *****
  • Posts: 1771
Re: Does GetPixel work with TBGRABitmap?
« Reply #3 on: December 19, 2019, 05:29:10 pm »
@user5

You can simplify your code. Your lines 15 & 16 could be pulled to one line.

From

Code: Pascal  [Select][+][-]
  1. bgra := TBGRABitmap.create(mybitmap.width,mybitmap.height);
  2. bgra.assign(mybitmap);
  3.  

To

Code: Pascal  [Select][+][-]
  1. bgra := TBGRABitmap.create(mybitmap);
  2.  

It creates a TBGRABitmap with height and width of myBitmap and then it make a copy.

Winni

 

TinyPortal © 2005-2018