如何在C ++中加载图像 [英] how to load images in c++

查看:93
本文介绍了如何在C ++中加载图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是c ++的初学者. IAM使用Visual Studio 2008 Professional.而且我必须在win32控制台应用程序上开发我的项目,但是我不知道需要哪种类型的代码才能在控制台上加载任何类型的图像,而且将包括哪些haeder文件,以及是否可以在其上加载图像有哪些限制?

iam a beginner in c++. iam using visual studio 2008 professional. and i have to develop my project on win32 console application but i dont know what type of code is needed to load any kind of image on the console furthermore what will be the haeder files included and what are the limitations whether an image can be loaded on the console or not....plz guide me.

推荐答案

您无法在控制台应用程序中加载图像,需要创建Windows应用程序并使用各种位图功能显示图像.您可以先在项目资源中添加一个简单的位图,然后使用
You cannot load images in console apps, you need to create a Windows app and use the various Bitmap functions to display images. You could start by adding a simple bitmap to the resources of your project and use LoadImage()[^].


我通常从控制台应用程序加载图像.执行诸如去偏斜和色彩还原之类的操作.

在控制台中显示1位图像也是一项琐碎的任务.

不久前,我放弃了LoadImage-发现增加的GDI +支持的格式值得过渡.


我时不时地忘记初始化GDI +,并且应用程序在启动时崩溃.否则,以下功能可以满足我的需求.


I commonly load images from console apps. Performing operations such as deskewing and colour reduction.

It''s also a trivial task to display 1 bit images in the console..

I gave-up on LoadImage a looong time ago - finding that the increased number of formats supported by GDI+ was worth the transition.


Every now and again I forget to initialize GDI+, and the app crashes upon startup. Otherwise, the following function performs adequetly for my needs.


// BMP, GIF, JPEG, PNG, TIFF, Exif, WMF, and EMF
HBITMAP mLoadImg(WCHAR *szFilename)
{
   HBITMAP result=NULL;

   Gdiplus::Bitmap* bitmap = new Gdiplus::Bitmap(szFilename,false);
   bitmap->GetHBITMAP(NULL, &result);
   delete bitmap;
   return result;
}



使用此功能之前,必须调用以下初始化代码:



Before you use this function you must call the following init-code:

static Gdiplus::GdiplusStartupInput gdiplusStartupInput;
static ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);



之后,您必须关闭GDI +



Afterwards, you have to shut-down GDI+

Gdiplus::GdiplusShutdown(gdiplusToken);




您需要包含gdiplus.h头文件并链接gdiplus库




You''ll need to include the gdiplus.h header file and link the gdiplus library


这篇关于如何在C ++中加载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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