简体   繁体   English

将PNG或JPG图像加载到CMFCToolBarImages中

[英]Load PNG or JPG images into CMFCToolBarImages

An MFC application creates an array 64*48 size BMP images and a MFC ribbon gallery loads them fine. MFC应用程序创建64 * 48尺寸的BMP图像数组,而MFC功能区库将它们加载得很好。 Since loading the BMPs take time I am trying to create a series of PNG images and then load them into the ribbon gallery. 由于加载BMP需要花费时间,因此我尝试创建一系列PNG图像,然后将其加载到功能区库中。

I tried saving the bitmaps in PNG format by changing the BITMAPINFOHEADER.biCompression property to BI_PNG but no image was saved. 我尝试通过将BITMAPINFOHEADER.biCompression属性更改为BI_PNG来将位图保存为PNG格式,但未保存任何图像。 I also tried saving the bitmap using CImage object in PNG format: 我也尝试使用CImage对象以PNG格式保存位图:

 CImage TempImageObj;
 TempImageObj.Attach(hbmp);
 hr = TempImageObj.Save(filename, Gdiplus::ImageFormatPNG);

This time images were saved in files but the CMFCToolBarImages object didn't load them. 这次将图像保存在文件中,但CMFCToolBarImages对象未加载它们。

Is it possible to create an image in PNG format(other than using CImage Save method) in MFC? 是否可以在MFC中创建PNG格式的图像(使用CImage Save方法除外)? Is it possible to load PNG images into CMFCToolBarImages object? 是否可以将PNG图像加载到CMFCToolBarImages对象中?

MFC can't create .png directly. MFC不能直接创建.png。 You can use CImage or any free image library like CxImage 您可以使用CImage或任何免费的图像库,例如CxImage

To open back the .png you can use CImage and then use it as HBITMAP object: 要打开.png,可以使用CImage然后将其用作HBITMAP对象:

CImage image;
image.Load( filename );   
HBITMAP hBmp = image; // Warning: image is still the data owner

toolbar.AddImage( hBmp);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM