Skip to content

GetRGBPixelAt

function

Delphi
function GetRGBPixelAt (x: LongInt; y: LongInt): LongInt;
C++Builder
System::LongInt __fastcall GetRGBPixelAt(System::LongInt x, System::LongInt y);
C#
public int GetRGBPixelAt(int x, int y);
VB.NET
Public Function GetRGBPixelAt(x As Integer, y As Integer) As Integer
C++/Qt
int GetRGBPixelAt (int x, int y);

Returns the RGB value of the pixel at the specified (x, y) location in the current video frame, with x between 0 and (VideoWidth - 1) and y between 0 and (VideoHeight - 1).

Note: this function must be invoked from one of the OnFrameOverlayUsing... events (e.g. from the OnFrameOverlayUsingDC event).

Each color component can be extracted from the returned value with the following code:

procedure TfrmMainForm.VideoGrabberFrameOverlayUsingDC(Sender: TObject;
  Dc: HDC; FrameNumber: Cardinal; FrameTime: Int64; FrameId: Integer);
var
  RGBValue: LongInt;
  R, G, B: LongInt;
  x, y: LongInt;
begin
  x := 10; // e.g. column 10
  y := 15; // and row 15
  RGBValue := VideoGrabber.GetRGBPixelAt (x, y);
  R := RGBValue and $FF;
  G := (RGBValue shr 8) and $FF;
  B := (RGBValue shr 16) and $FF;
end;
void __fastcall TfrmMainForm::VideoGrabberFrameOverlayUsingDC(
    TObject *Sender, HDC Dc, DWORD FrameNumber, Int64 FrameTime,
    int FrameId)
{
    int RGBValue, R, G, B, x, y;
    x = 10; // e.g. column 10
    y = 15; // and row 15
    RGBValue = VideoGrabber->GetRGBPixelAt (x, y);
    R = RGBValue & 0xFF;
    G = (RGBValue >> 8) & 0xFF;
    B = (RGBValue >> 16) & 0xFF;
}
private void axVideoGrabberNET1_OnFrameOverlayUsingDC(object sender, Axvidgrab_NET.IVideoGrabberNETEvents_OnFrameOverlayUsingDCEvent e)
{
    // ...
    Color RGBColor = System.Drawing.ColorTranslator.FromWin32 (axVideoGrabberNET1.GetRGBPixelAt(10, 15));
    textBoxR.Text = RGBColor.R.ToString();
    textBoxG.Text = RGBColor.G.ToString();
    textBoxB.Text = RGBColor.B.ToString();
    // ...
}