Mat to Bitmap

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Mat to Bitmap

Arturo Silva
Hi
Please, help me.

Bitmap* ASVideoCapture::getBitmapFromMat(Mat i_Mat) {

                assert(mb_InitDone);

             

                PixelFormat e_Format;

                switch (i_Mat.channels())

                {

                case 1: e_Format = PixelFormat8bppIndexed; break;

                case 3: e_Format = PixelFormat24bppRGB;    break;

                case 4: e_Format = PixelFormat32bppARGB;   break;

                default: cout << "Image format not supported." << endl;

             

                }

                

                cv::Size size = i_Mat.size();

                Gdiplus::Bitmap pi_Bmp (size.width, size.height, i_Mat.step1(), e_Format, i_Mat.data);

 

                Gdiplus::BitmapData i_Data;


                Gdiplus::Rect k_Rect(0, 0, i_Mat.cols, i_Mat.rows);

                

                switch (pi_Bmp.LockBits(&k_Rect, ImageLockModeWrite, e_Format, &i_Data))

                {

                                case Ok:  cout << "Ok LockBits." << endl; break;

                                case GenericError: cout << "GenericError." << endl; break;

                                case InvalidParameter: cout << "Invalid Parameter." << endl; break;

                                default: cout << "Other problem." << endl; break;

                } 

 

                pi_Bmp.UnlockBits(&i_Data);


                return &pi_Bmp;

 
}
 It does not work

 

Un abrazo.
Cel.: +59169804711Skype: david.arturo.silva
Reply | Threaded
Open this post in threaded view
|

Re: Mat to Bitmap

Francisco Ares
Look at the declaration

Gdiplus::Bitmap pi_Bmp ...

pi_Bmp, as it is created inside this method, it is automatically destroyed
at the end of it's execution.

Consider creating it at the caller object and passing it as reference, or
as a member of the class.

Hope this helps,
Francisco


Em qui, 28 de mar de 2019 06:09, Arturo Silva [hidden email]
[OpenCV] <[hidden email]> escreveu:

>
>
> Hi
>
> Please, help me.
>
> Bitmap* ASVideoCapture::getBitmapFromMat(Mat i_Mat) {
>
>                 assert(mb_InitDone);
>
>
>
>                 PixelFormat e_Format;
>
>                 switch (i_Mat.channels())
>
>                 {
>
>                 case 1: e_Format = PixelFormat8bppIndexed; break;
>
>                 case 3: e_Format = PixelFormat24bppRGB;    break;
>
>                 case 4: e_Format = PixelFormat32bppARGB;   break;
>
>                 default: cout << "Image format not supported." << endl;
>
>
>
>                 }
>
>
>
>                 cv::Size size = i_Mat.size();
>
>                  (size.width, size.height, i_Mat.step1(), e_Format,
> i_Mat.data);
>
>
>
>                 Gdiplus::BitmapData i_Data;
>
>                 Gdiplus::Rect k_Rect(0, 0, i_Mat.cols, i_Mat.rows);
>
>
>
>                 switch (pi_Bmp.LockBits(&k_Rect, ImageLockModeWrite,
> e_Format, &i_Data))
>
>                 {
>
>                                 case Ok:  cout << "Ok LockBits." << endl;
> break;
>
>                                 case GenericError: cout << "GenericError."
> << endl; break;
>
>                                 case InvalidParameter: cout << "Invalid
> Parameter." << endl; break;
>
>                                 default: cout << "Other problem." << endl;
> break;
>
>                 }
>
>
>
>                 pi_Bmp.UnlockBits(&i_Data);
>
>                 return &pi_Bmp;
>
>
> }
>
> * It does not work*
>
>
>
> Un abrazo.
>
> Cel.: +59169804711
> Skype: david.arturo.silva
>
>
>