可以使用loadimage windows函数来加载.bmp图像以外的其他图像,例如它可以加载.jpg或.png文件吗? [英] can loadimage windows function be used to load other images other than .bmp images for instance can it load .jpg or .png files?

查看:764
本文介绍了可以使用loadimage windows函数来加载.bmp图像以外的其他图像,例如它可以加载.jpg或.png文件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以使用loadimage windows函数加载.bmp图像以外的其他图像,例如可以加载.jpg或.png文件吗?

can loadimage windows function be used to load other images other than .bmp images for instance can it load .jpg or .png files?

推荐答案

尽可能请参阅文档 [ ^ ]你只能加载位图,光标和图标。



要加载jpg文件,你需要先将它转换为位图。周围有许多图书馆,可以为您做到这一点。只需在CodeProject上搜索一下。
As you can see in the documentation[^] you can only load bitmaps, cursors, and icons.

To load a jpg-file you will need to convert it first to a bitmap. There are numerous libraries around, which can do that for you. Just search a little on CodeProject.


没有。 LoadImage无法加载任何非常现代的东西。你可以加载bmp,.ico,.cur,这就是它。自从10多年以来,Windows已经包含了GDI +子系统,它或多或少是一个面向对象的改进版GDI。 GDI +可以毫无问题地加载这些其他图像 - 加载Windows本身显示的任何内容 - 包括png,jpg,emf,wmf和其他一些。



这样做相当简单 - 请参阅下面的使用示例。确保链接到Gdiplus库。另请注意,您只需要为每个程序启动/关闭Gdi +一次,这使得我的示例基本上是一个使用gdi +的1行程序。



No. LoadImage cant load anything that's terribly modern. You can load bmp, .ico, .cur and that's about it. Since over 10 years now Windows has included the GDI+ subsystem, which is more or less, an object-oriented, improved version of GDI. GDI+ can load these other images without a problem - loading anything that Windows will display natively - including png, jpg, emf, wmf and a bunch of others.

Doing so is rather trivial - See below for an example of use. Make sure you link against the Gdiplus library. Also note, you just need to startup/shutdown Gdi+ once per program, which makes my example essentially a 1 line program that uses gdi+.

#include <gdiplus.h>

using namespace Gdiplus;

// BMP, GIF, JPEG, PNG, TIFF, Exif, WMF, and EMF
HBITMAP mLoadImageFile(wchar_t *filename)
{
    HBITMAP result = NULL;
    Bitmap bitmap(filename, false);
    bitmap.GetHBITMAP(0, &result);
    return result;
}

int main()
{
    GdiplusStartupInput gdiplusStartupInput;
    ULONG_PTR           gdiplusToken;
    GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

    HBITMAP mBkgImg = mLoadImage(L"forrest.jpg");

   	GdiplusShutdown(gdiplusToken);

}


这篇关于可以使用loadimage windows函数来加载.bmp图像以外的其他图像,例如它可以加载.jpg或.png文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆