怎样显示Jpg,bmp,Gif图像文件
2011-06-09 14:01
483 查看
LoadImage只能加载bmp,ico,cur文件,但是对于jpg,gif等文件则无能为力,下面就是介绍用VC怎么显示jpg,gif,bmp文件
1:LoadImage
HBITMAP hBitmap=(HBITMAP)::LoadImage(AfxGetInstanceHandle(),"128.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_DEFAULTCOLOR|LR_DEFAULTSIZE);
2:GdiPlus
A. 在stdafx.h中或者cpp文件的头部引入下面两条语句
#include <gdiplus.h>
using namespace Gdiplus;
B. 在项目属性-》连接器-》输入-》附加依赖项中加入gdiplus.lib
C. 初始化gdiplus(一般在InitInstance或者OnInitDialog中加入)
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
D.实现在一个Static(IDC_STATIC1)中显示,在其它地方也可以只要具有Window
RECT rect;
HDC hdc;
PAINTSTRUCT ps;
GetDlgItem(IDC_STATIC1)->GetClientRect(&rect);
hdc = GetDlgItem(IDC_STATIC1)->GetWindowDC()->m_hDC;
Graphics graphics(hdc);
//由于Gdiplus::Image img()语句的参数必须是wchar_t *的形式,下面就是将文件名strFileName从char *转换为wchar_t *
int wcsLen;
wchar_t* wszFileName;
wcsLen = ::MultiByteToWideChar(CP_ACP, NULL, strFileName, strlen(strFileName), NULL, 0);
wszFileName = new wchar_t[wcsLen + 1];
::MultiByteToWideChar(CP_ACP, NULL, strFileName, strlen(strFileName), wszFileName, wcsLen);
wszFileName[wcsLen] = '/0';
Gdiplus::Image img(wszFileName);
graphics.DrawImage(&img, 0, 0, rect.right - rect.left, rect.bottom - rect.top);
::ReleaseDC(GetDlgItem(IDC_STATIC1)->m_hWnd, hdc);
delete wszFileName;
1:LoadImage
HBITMAP hBitmap=(HBITMAP)::LoadImage(AfxGetInstanceHandle(),"128.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_DEFAULTCOLOR|LR_DEFAULTSIZE);
2:GdiPlus
A. 在stdafx.h中或者cpp文件的头部引入下面两条语句
#include <gdiplus.h>
using namespace Gdiplus;
B. 在项目属性-》连接器-》输入-》附加依赖项中加入gdiplus.lib
C. 初始化gdiplus(一般在InitInstance或者OnInitDialog中加入)
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
D.实现在一个Static(IDC_STATIC1)中显示,在其它地方也可以只要具有Window
RECT rect;
HDC hdc;
PAINTSTRUCT ps;
GetDlgItem(IDC_STATIC1)->GetClientRect(&rect);
hdc = GetDlgItem(IDC_STATIC1)->GetWindowDC()->m_hDC;
Graphics graphics(hdc);
//由于Gdiplus::Image img()语句的参数必须是wchar_t *的形式,下面就是将文件名strFileName从char *转换为wchar_t *
int wcsLen;
wchar_t* wszFileName;
wcsLen = ::MultiByteToWideChar(CP_ACP, NULL, strFileName, strlen(strFileName), NULL, 0);
wszFileName = new wchar_t[wcsLen + 1];
::MultiByteToWideChar(CP_ACP, NULL, strFileName, strlen(strFileName), wszFileName, wcsLen);
wszFileName[wcsLen] = '/0';
Gdiplus::Image img(wszFileName);
graphics.DrawImage(&img, 0, 0, rect.right - rect.left, rect.bottom - rect.top);
::ReleaseDC(GetDlgItem(IDC_STATIC1)->m_hWnd, hdc);
delete wszFileName;
相关文章推荐
- 使用IPicture的OLE实现读取和显示BMP,GIF,JPG,ICO,EMF,WMF图像
- 在MFC应用程序中显示JPG/GIF图像文件
- VC++ 2005中显示jpg,bmp,gif图像的方法
- 利用COM组件IPicture读取jpg、gif、bmp图片文件数据和显示图片的两个函数
- VC 中BMP、JPG、GIF图像的显示
- 使用IPicture接口读取和显示BMP,GIF,JPG,ICO,EMF,WMF图像
- 如何在MFC中显示jpg.gif.bmp等类型的图像
- VC 中BMP、JPG、GIF图像的显示
- 使用IPicture接口读取和显示BMP,GIF,JPG,ICO,EMF,WMF图像 (转)
- BMP、JPG、GIF图像的显示
- VC下显示JPG,BMP,GIF等图像格式
- 使用IPicture的OLE实现读取和显示BMP,GIF,JPG,ICO,EMF,WMF图像
- VC下显示JPG,BMP,GIF等图像格式(转载)
- VC下显示JPG,BMP,GIF等图像格式
- 在MFC应用程序中显示JPG/GIF图像文件
- 使用IPicture接口读取和显示BMP,GIF,JPG,ICO,EMF,WMF图像
- bmp,gif,jpg等图像的文件格式
- VC中导入图像(BMP,JPG,GIF)并显示的方法
- 利用COM组件IPicture读取jpg、gif、bmp图片文件数据和显示图片
- 利用IPicture接口实现显示BMP/JPG/GIF图像