I want to create HBITMAP from byte array with JPEG format.
I have searched but I only can create it from bitmap file as
HBITMAP hbm = (HBITMAP)LoadImage(NULL,"fileName",IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION);
Can someone show me how to do it?
I found the following code //http://katahiromz.web.fc2.com/win32/loadjpeg.html
The red and blue were swapped, so here is a corrected version with the colours corrected. It uses jpeglib, so you must first compile that. If you need only to convert a buffer, then you can skip the line that loads the file - the details of converting should be the same.
Just use GDIplus. It supports loading JPEGs, and some other stuff feels much more logically
http://msdn.microsoft.com/en-us/library/ms533830%28v=vs.85%29.aspx
Use "Bitmap" class. When you have the jpeg in a buffer, you need to read it by a stream.
MFC provides a
CImage
class that wraps a bitmap object. It provides convenience methods to load and save images in a host of formats, including JPEG, GIF, BMP, and PNG.So the first order of business is obtaining a
CImage
object representing yourHBITMAP
. You can do this by calling theAttach
method and passing the handle.But in this case, it looks like you can skip that entirely and just have the
CImage
object load your image from the file directly. Use theLoad
method for that.Once you've got a
CImage
object representing your image, just call theSave
method and specify the desired file name with the appropriate extension. According to the documentation:Sample code:
You can also reverse this pattern, using the
Load
method to load JPEG files and theSave
method to save BMP files.