Hello to All,
I apologise if my post sounds too simple for some of you, but I am a novice in Pascal programming.
I am testing a USB camera with DirectShow, using the DSPACK, and I encountered some problems.
I can visualise the live picture of the camera in a VideoWindow, but I would like to superipose over the
live picture a simple crosshair (see the attached picture). I am using a VMRBitmap to transfer the drawing
to mix it with the live video image.
I draw the pair of horizontal and vertical red lines which form a crosshair on a Bitmap (TBitmap) with white
background. The bitmap could be transferred to the VMRABitmap with the Loadbitmap procedure. However,
this directly is not working (I mean, it does not gives result). I am using the vmrbSrcColorKey and ColorKey
for the white background, this should remain transparent over the live video image, only the crosshair should
be visible from the entire bitmap overlayed on the video. This works correctly under Delphi.
// crossBitmap is a TBitmap with the red haircross on it over a white background, it is created previously
try
VMRBitmap.LoadBitmap(crossBitmap);
VMRBitmap.Source := VMRBitmap.Canvas.ClipRect;
VMRBitmap.Options := VMRBitmap.Options + [vmrbSrcColorKey];
VMRBitmap.ColorKey := clWhite;
VMRBitmap.DrawTo(0,0,1,1, 1);
finally
crossBitmap.Free;
end;
I found a "brute force" way to solve this, first I am saving the bitmap to a file, load the file, and pass the bitmap to the
VMRABitmap. Yes, I admit, this is not a correct way, and I would not use this, but for now it is the only working solution.
The crosshair position has to be moved on the video image, so I can't save and load every time the bitmap.
// crossBitmap is a TBitmap with the red haircross on it over a white background, it is created previously
crossBitmap.SaveToFile('test.bmp');
try
crossBitmap.LoadFromFile('test.bmp');
VMRBitmap.LoadBitmap(crossBitmap);
VMRBitmap.Source := VMRBitmap.Canvas.ClipRect;
VMRBitmap.Options := VMRBitmap.Options + [vmrbSrcColorKey];
VMRBitmap.ColorKey := clWhite;
VMRBitmap.DrawTo(0,0,1,1, 1);
finally
crossBitmap.Free;
end;
I have a clue, that this behaviour is due to the native TBitmap format of Lazarus, which is different than the Windows
bitmap, and since VMRABitmap is expecting a Windows type bitmap, it does not mix over the video the desired content.
But I am not able to find a solution. Can anyone recommend another way?
I also noticed the problem mentioned on the first page of the topic, the VMRBitmap.LoadEmptyBitmap
does not work for me either. Instead, to clear the overlay on the video, I am using the same trick, I create
a bitmap, and pass it to VMRBitmap. This could be a compromise, but is acceptable.
//emptyBitmap is a TBitmap
emptyBitmap := TBitmap.Create;
VMRBitmap.LoadEmptyBitmap(400,300,pf24bit ,clWhite); //a pixel formattal van valami baj
//VMRBitmap.LoadBitmap( emptyBitmap );
VMRBitmap.Source := VMRBitmap.Canvas.ClipRect;
VMRBitmap.DrawTo(0,0,1,1,0);
emptyBitmap.Free;
end;
Thanks in advance,
Gyuri