[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5471
  • Last Modified:

MFC: Convert CImage to HBITMAP

How to convert from CImage to HBITMAP?

CImage image;
HRESULT sc=image.Load(stringload);
HBITMAP hbmp=image.Detach();

This doesn't work! Any solution to this is very welcomed!

The opposite works very well:

CImage image;
image.Attach(hBmp);
HRESULT sc=image.Save(stringsave);
0
buddird
Asked:
buddird
  • 3
  • 3
1 Solution
 
jkrCommented:
Just use 'CImage::operator HBITMAP()'  (http://msdn2.microsoft.com/en-us/library/2czhsdwe(VS.80).aspx) to do that, i.e.
CImage image;
HRESULT sc = image.Load(stringload);
HBITMAP hbmp = (HBITMAP) image;

Open in new window

0
 
buddirdAuthor Commented:
Thank you! I have also seen this, but it won't help me.

Your suggestion can be compiled, but when I run it I get out of memory when trying to execute:

sc = ::OleCreateStaticFromData(this, IID_IOleObject, OLERENDER_FORMAT, &m_fromat, pOleClientSite, pStorage, (void **)&pOleObject);

When I use HBITMAP, which I got from the clipboard the same works perfectly. Every time.

What is the difference between CImage HBITMAP and HBITMAP from clipboard? Any work around?

0
 
jkrCommented:
Hm, I cannot see any HBITMAP in the above line...
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
buddirdAuthor Commented:
You are right! It is the line of code which fails because I have another HBITMAP than from the clipboard. In short I am using CImageDataObject by Hani Atassi. It is a class for inserting HBITMAP into CRichEditCtrl. ("Interface to be used in inserting bitmap to the RichEdit Control.")

As input to the class I have HBITMAP and a pointer to IRichEditOle. When I use HBITMAP from the clipboard everything works every time, but never with HBITMAP from CImage.

What I am going to do is to insert an image from disk into the CRichEditCtrl.

That's why I need your help. Thank you in advance.
0
 
jkrCommented:
Well, take a look at http://www.codeproject.com/KB/edit/COleRichEditCtrl.aspx ("A Rich Edit Control That Displays Bitmaps and Other OLE Objects") on how to display stuff in such a control
0
 
buddirdAuthor Commented:
Thank you! That was what I needed. You get excellent for this:)
0

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now