在StdAfx.h中静态调用diplus.lib
#ifndef ULONG_PTR
#define ULONG_PTR unsigned long*
#include "GdiPlus.h"
using namespace Gdiplus;
#pragma comment(lib, "gdiplus.lib")
#endif在CAPP.h中定义成员变量:ULONG_PTR m_gdiplusToken;在InitInstance中加入初始化GDI+的函数:
CWinApp::Instance();
Gdiplus::GdiplusStartupInput m_gdiplusStartupInput;
GdiplusGdiplusStartup(&m_gdiplusToken, &m_gdiplusStartupInput, NULL); 在ExitInstance中加入结束GDI+使用的函数:
Gdiplus::GdiplusShutdown(m_gdiplusToken);用Image,无论从IStream还是从文件中输入,编译通过,执行时出错,不知道该怎么办?
#ifndef ULONG_PTR
#define ULONG_PTR unsigned long*
#include "GdiPlus.h"
using namespace Gdiplus;
#pragma comment(lib, "gdiplus.lib")
#endif在CAPP.h中定义成员变量:ULONG_PTR m_gdiplusToken;在InitInstance中加入初始化GDI+的函数:
CWinApp::Instance();
Gdiplus::GdiplusStartupInput m_gdiplusStartupInput;
GdiplusGdiplusStartup(&m_gdiplusToken, &m_gdiplusStartupInput, NULL); 在ExitInstance中加入结束GDI+使用的函数:
Gdiplus::GdiplusShutdown(m_gdiplusToken);用Image,无论从IStream还是从文件中输入,编译通过,执行时出错,不知道该怎么办?
解决方案 »
- 哪里有VC++数字图像处理的视频教程
- 请问如何给OLEDB的 _ADOCommand传递参数
- 求助VC 汉字字模提取 HZK16
- dll中调用LoadBitmap失败!
- 用DirectDraw创建带有Alpha通道的Suface???
- 有难度的问题~~~~~
- 请问如何将UTF-8编码的字符串转换为GB编码?
- 一个关于视图作画的问题,急等!!!!!!!!!!!!!!!!
- 如何将.cpp文件打包成.exe文件
- 探讨和请教一个socket的端口绑定问题,编程高手千万不能错过,也许你还没发现这个问题~!
- 请问如何在socket中发送带结构体的数据(结构体中带有指针)?
- 请问怎么在OLEDB中带参数访问多个表?
#include <Objbase.h>
#include <Windows.h>
#include <Gdiplus.h>
#include <GdiPlusEnums.h>
using namespace Gdiplus;
#pragma comment(lib,"gdiplus")
int GetCodecClsid(const WCHAR*, CLSID*);
HRESULT __fastcall AnsiToUnicode(LPCSTR pszA, LPOLESTR* ppszW)
{
ULONG cCharacters;
DWORD dwError;
if (NULL == pszA)
{
*ppszW = NULL;
return NOERROR;
}
cCharacters = strlen(pszA)+1;
*ppszW = (LPOLESTR) CoTaskMemAlloc(cCharacters*2);
if (NULL == *ppszW)
return E_OUTOFMEMORY;
if (0 == MultiByteToWideChar(CP_ACP, 0, pszA, cCharacters,*ppszW, cCharacters))
{
dwError = GetLastError();
CoTaskMemFree(*ppszW);
*ppszW = NULL;
return HRESULT_FROM_WIN32(dwError);
}
return NOERROR;
}int main(int argc, char* argv[])
{
int n_ret=0;
printf("%s can convert jpg, png, gif, tiff to gif file.\n if it works, it is written by masterz, otherwise I don't know who write it\n",argv[0]);
if(argc!=3)
{
printf("usage:%s gif_filename source_image_filename\n",argv[0]);
return -1;
}
GdiplusStartupInput gdiplusStartupInput;
ULONG gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
{
CLSID codecClsid;
Status stat;
EncoderParameters encoderParameters; GetCodecClsid(L"image/gif", &codecClsid);
encoderParameters.Count = 0;
LPOLESTR bstr_src_img;
LPOLESTR bstr_dst_fn;
AnsiToUnicode(argv[1],&bstr_dst_fn);
AnsiToUnicode(argv[2],&bstr_src_img);
Image image(bstr_src_img);
stat =image.Save(bstr_dst_fn, &codecClsid, &encoderParameters);
if(stat == Ok)
{
n_ret=0;
wprintf(L"%s saved successfully.\n",bstr_dst_fn);
}
else
{
n_ret=-2;
wprintf(L"%d Attempt to save %s failed.\n", stat, bstr_dst_fn);
}
CoTaskMemFree(bstr_dst_fn);
CoTaskMemFree(bstr_src_img);
}
GdiplusShutdown(gdiplusToken);
return 0;
} // main
int GetCodecClsid(const WCHAR* format, CLSID* pClsid)
{
UINT num = 0; // number of image encoders
UINT size = 0; // size of the image encoder array in bytes ImageCodecInfo* pImageCodecInfo = NULL; GetImageEncodersSize(&num, &size);
if(size == 0)
return -1; // Failure pImageCodecInfo = (ImageCodecInfo*)(malloc(size));
if(pImageCodecInfo == NULL)
return -1; // Failure GetImageEncoders(num, size, pImageCodecInfo); for(UINT j = 0; j < num; ++j)
{
if( wcscmp(pImageCodecInfo[j].MimeType, format) == 0 )
{
*pClsid = pImageCodecInfo[j].Clsid;
return j; // Success
}
} // for return -1; // Failure} // GetCodecClsid
//in order to compile this program, you need to download microsoft platform sdk from http://www.microsoft.com/msdownload/platformsdk/sdkupdate/downlevel.htm
//also download gdiplus.dll and put it at the same directory as the executable.
//http://www.microsoft.com/downloads/release.asp?releaseid=32738
//Platform SDK Redistributable: GDI+ RTM //sample usage: img2gif a.gif src.bmp
在程序中可以进行画直线等操作,也可以用 Btmap bitmap(L"Texture.jpg"); 来显示图片,但是若使用Image image(L"Texture.jpg");来显示图片,编译通过以后,执行时出错,不知道该怎样解决。