Visual C++ Developer Center >
Visual C++ Forums
>
Visual C++ General
>
Image capture using mixed mode c++/cli
Image capture using mixed mode c++/cli
- I have an ActiveX control that when called returns a handle to image memory. In native code use, that memory is locked via GlobalLock to be used as image data in a graphic object. The return type of the GlobalLock function is casted to a pointer to BITMAPINFOHEADER
LPBITMAPINFOHEADER Info = (LPBITMAPINFOHEADER)GlobalLock(Handle);
This is lifted from an MFC app that perfroms image capture from an USB imaging device which I want to change into a CLR WinForm project without using MFC.
I am trying to use the variable Info to create Bitmap data for use in a WinForm with LPBITMAPINFOHEADER as the source of image data
The disconnect is getting from GDI functions (or GDI+ classes) to the System::Drawing namspace classes. GDI+ has one mehod that is useful. The list of constructors has creating a Bitmap from a BITMAPINFO and data array.
The problem is in the constructor. I get an error: error C2061: syntax error : identifier '{ctor}'
The call is as follows:
bm = new Gdiplus::Bitmap::Bitmap(bmi, _imgPtr->Bits);
bm is defined earlier as:
Gdiplus::Bitmap* bm;
The alternative is to call explicitly the FromBITMAPINFO method:
bm = Gdiplus::Bitmap::FromBITMAPINFO(bmi, _imgPtr->Bits);
This builds but I need to get Bitmap to draw an image to a picturebox on a form. If I have a returned Bitmap in memory how can I get that into a picture box wihout writing to a file? The Image and Graphics classes don't look like a solution or maybe I'm missing something.
Thanks in advance
Jer 29:11
Answers
For other community members, the solution can be found on another discussion
http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/15b18c4b-a8ba-4c8f-9db8-d0a823c4b42e
Thanks,
Rong-Chun Zhang
MSDN Subscriber Support in Forum
If you have any feedback on our support, please contact msdnmg@microsoft.com
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.- Marked As Answer byRong-Chun ZhangMSFT, ModeratorThursday, November 12, 2009 11:27 AM
All Replies
- bm = new Gdiplus::Bitmap(bmi, _imgPtr->Bits);
- Hello Al_S
Thanks for your post.
If you can get the gdiplus::Bitmap object, you can the call the Bitmap::GetHBITMAP Method to get the handle to bitmap(GDI), then in managed code call the Image.FromHbitmap Method (IntPtr) to get the image.
More info
http://msdn.microsoft.com/en-us/library/ms536295%28VS.85%29.aspx
http://msdn.microsoft.com/en-us/library/k061we7x.aspx
Thanks,
Rong-Chun Zhang
MSDN Subscriber Support in Forum
If you have any feedback on our support, please contact msdnmg@microsoft.com
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us. bm = new Gdiplus::Bitmap(bmi, _imgPtr->Bits);
Right! I had one too many classes there.
bm = new Gdiplus::Bitmap::Bitmap(bmi, _imgPtr->Bits);
Jer 29:11Hello Al_S
Thanks for your post.
If you can get the gdiplus::Bitmap object, you can the call the Bitmap::GetHBITMAP Method to get the handle to bitmap(GDI), then in managed code call the Image. FromHbitmap Method (IntPtr) to get the image.
More info
http://msdn.microsoft.com/en-us/library/ms536295%28VS.85%29.aspx
http://msdn.microsoft.com/en-us/library/k061we7x.aspx
Thanks,
Rong-Chun Zhang
MSDN Subscriber Support in Forum
If you have any feedback on our support, please contact msdnmg@microsoft.com
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
I am getting ambiguous symbol errors:
Error 1 error C2872: 'Bitmap' : ambiguous symbol Form1.h 271 CameraViewer
Error 2 error C2872: 'Image' : ambiguous symbol 271 CameraViewer
Code so far:
bm = new Gdiplus::Bitmap(bmi, _imgPtr->Bits);
Gdiplus::Color col;
HBITMAP hBM;
bm->GetHBITMAP(col, &hBM);
Bitmap image = Image::FromHbitmap((IntPtr)hBM);
The IDE shows that image is part of System::Drawing::Bitmap.
Jer 29:11- I changed the calls to better define the member.
System::Drawing::Bitmap^ image = System::Drawing::Image::FromHbitmap((IntPtr)hBM);
Is this necessary or is there a better way to remove ambiguous errors?
How can I capture color settings from what I have in the image data from the native code? Gdiplus::Color col = Argb 0xff000000. As expected the image is grey.
I suspect I need more calls into GDI+ to get the image information back into a picturebox.
Jer 29:11 - I think the reason I don't have a valid image is due to mixing GDI+ on a GDI memory HBITMAP
I found this article about interop between GDI+ and GDI
Jer 29:11 - Hello Al_S,
Is the problem resolved. If not, could you please send me a simple project that can reproduce this issue to my mail box(v-rzhang[at]microsoft.com)? I will dig into it and keep you updated.
Thanks,
Rong-Chun Zhang
MSDN Subscriber Support in Forum
If you have any feedback on our support, please contact msdnmg@microsoft.com
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us. - Hope what I sent illustrates the issue.
Thanks.
Jer 29:11 For other community members, the solution can be found on another discussion
http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/15b18c4b-a8ba-4c8f-9db8-d0a823c4b42e
Thanks,
Rong-Chun Zhang
MSDN Subscriber Support in Forum
If you have any feedback on our support, please contact msdnmg@microsoft.com
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.- Marked As Answer byRong-Chun ZhangMSFT, ModeratorThursday, November 12, 2009 11:27 AM


