 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Andrea Guest
|
Posted: Sat Jan 24, 2004 11:59 am Post subject: Read Pixel Color from control |
|
|
Hi, all.
I' try-ing to read some pixel color in a visible control.
I try it with a canvas, but it return always -1.
canv-Pixels[0][0];
I see the x,y coordinate are on ClipRect ( 0,0 - 243,149) so I don't
understand why the code return -1.
Any hints?
Many thanks,
Andrea Peri.
|
|
| Back to top |
|
 |
Damon Chandler (TeamB) Guest
|
Posted: Fri Jan 30, 2004 8:08 am Post subject: Re: Read Pixel Color from control |
|
|
Hi Andrea,
When you call the Pixels property on a TCanvas object for a particular
window, you need to make sure that the point in the window is visible
and not covered by another window or a child windowed control. For
example, calling Form1->Canvas->Pixels[x][y] will return -1 if some
other window or windowed control (e.g., a TPanel) occupies the point
(x,y) on Form1. You can get around this limitation by using a Canvas
associated with the screen...
#include <memory>
void __fastcall TForm1::Button1Click(TObject *Sender)
{
std::auto_ptr<TCanvas> ScreenCanvas(new TCanvas());
ScreenCanvas->Handle = GetDC(NULL);
try
{
TPoint const P = ClientOrigin;
ShowMessage(ScreenCanvas->Pixels[P.x][P.y]);
}
__finally
{
ReleaseDC(NULL, ScreenCanvas->Handle);
ScreenCanvas->Handle = NULL;
}
}
HTH,
Damon (TeamB)
Andrea wrote:
| Quote: | I' try-ing to read some pixel color in a visible control.
I try it with a canvas, but it return always -1.
canv-Pixels[0][0];
I see the x,y coordinate are on ClipRect ( 0,0 - 243,149) so I don't
understand why the code return -1.
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|