display vmem output in a pictureBox
Posted: 08 Feb 2010 17:44
Hello everybody, I finally managed to link unmanaged libVLC with managed Winforms and setup a little project where the vmem unlock callback calls a marshalled delegate which invoke an event whose handler display the frame in a picturebox. I am doing this because I need to display the video with text and polilynes overlaying on the frames and syncrhonization between polylines and video is quite important.
The problem is that at the moment I am displaying the image on the form calling the SetPixel method for each pixel:
but as you can imagine this is very slow...
I'd like to find a way to access the Image directly... someone told me to use GCHandle to pin the pixel of the Image, but I don't know what to do!
I have also found this link which seems quite useful http://www.bobpowell.net/lockingbits.htm
It would be great to do something like BitmapData->Scan0 = context->pixels so that there is no overhead for rearranging the pixel values.
Yet I don't know if this is possible.
There is also another problem, I've looked for documentation for vmem-chroma but I found nothing... Anyway RV32 gives me BGRA data, but .NET Image data is arranged in ARGB, is there a way to tell vmem to arrange the data as I want so that I can save the time or the rearrangement? I think it is the main cause of slowness and my project should work realtime.
The problem is that at the moment I am displaying the image on the form calling the SetPixel method for each pixel:
Code: Select all
Bitmap bmp(VIDEO_WIDTH, VIDEO_HEIGHT, Imaging::PixelFormat::Format32bppRgb);
for(int x=0; x<VIDEO_WIDTH; x++)
for(int y=0; y<VIDEO_HEIGHT; y++)
{
int a, r, g, b;
b=context->pixels[(y*VIDEO_WIDTH+x)*4+0];
g=context->pixels[(y*VIDEO_WIDTH+x)*4+1];
r=context->pixels[(y*VIDEO_WIDTH+x)*4+2];
a=context->pixels[(y*VIDEO_WIDTH+x)*4+3];
bmp.SetPixel(x, y, System::Drawing::Color::FromArgb(a, r, g, b));
}
this->pictureBox1->Image=bmp.GetThumbnailImage(VIDEO_WIDTH, VIDEO_HEIGHT, nullptr, System::IntPtr::Zero);
System::Drawing::Graphics ^g = System::Drawing::Graphics::FromImage(this->pictureBox1->Image);
g->DrawImage(bmp.GetThumbnailImage(VIDEO_WIDTH, VIDEO_HEIGHT, nullptr, System::IntPtr::Zero), 0, 0);
System::Drawing::Pen ^p = gcnew System::Drawing::Pen(System::Drawing::Color::Green, 4);
g->DrawLine . . . bla bla bla
I'd like to find a way to access the Image directly... someone told me to use GCHandle to pin the pixel of the Image, but I don't know what to do!
I have also found this link which seems quite useful http://www.bobpowell.net/lockingbits.htm
It would be great to do something like BitmapData->Scan0 = context->pixels so that there is no overhead for rearranging the pixel values.
Yet I don't know if this is possible.
There is also another problem, I've looked for documentation for vmem-chroma but I found nothing... Anyway RV32 gives me BGRA data, but .NET Image data is arranged in ARGB, is there a way to tell vmem to arrange the data as I want so that I can save the time or the rearrangement? I think it is the main cause of slowness and my project should work realtime.