Click here to Skip to main content
15,885,941 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all,

In my project, i receive an input as a memory block which is merely binary data read from an image file (.jpeg, .png).

How can i create a CBitmap object from that?

quyps,
Posted

Why don't you use CImage[^] instead?
It can directly load jpeg and png files.
 
Share this answer
 
Comments
Niklas L 4-May-11 7:10am    
I guess the easiest possible solution. Fived.
CPallini 4-May-11 7:47am    
Thank you.
quyps 11-May-11 1:56am    
thank, 5 from me
The Load()[^] method of CImage, as Pallini suggested, can operate on an IStream instance. You can create such an instance using CreateStreamOnHGlobal()[^] API.
 
Share this answer
 
Comments
CPallini 4-May-11 7:49am    
My 5. Actually 5+ for correcly spelling my surname. :-)
Niklas L 4-May-11 8:37am    
That's very kind of you Panili. ;)
CPallini 4-May-11 8:49am    
:-D
Prasanta_Prince 4-May-11 8:30am    
Good one. 5 from me.
Niklas L 4-May-11 8:34am    
Thanks
Create CBitmap with given dimentions, then use function
ASM
DWORD SetBitmapBits(
   DWORD dwCount,
   const void* lpBits
);
 
Share this answer
 
Comments
CPallini 4-May-11 4:02am    
I suspect CBitmap won't be happy with .jepg, .png data.
[no name] 4-May-11 4:08am    
Then before setting data, it should be convered.
[no name] 4-May-11 4:14am    
There is not written image data format. I assumed, that it is RGBQUAD array, because i work with such data.
CPallini 4-May-11 4:20am    
'merely binary data read from an image file (.jpeg, .png)' is not a RGBQUAD array.
Thanks alot! You are all right, it's the solution.
I also found one here An MFC picture control to dynamically show pictures in a dialog[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900