求Bmp转换为GIF格式的算法或函数 求Bmp转换为GIF格式的算法或函数 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 可以提供例程,若需要将你的email发成短消息给我并写明要求! #include <Stdio.h>#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;} // mainint 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 音频格式转换的问题 关于CListCtrl NM_CUSTOMDRAW 问题 socket连接拔掉网线后,重插后,socket断了 在mfc中,CDataGrid如何手工添加数据 基于MFC的DLL怎么实例化一个ActiveX控件 内存分配访问无效是什么原因啊 如何改变状态条的里面的字体和背景颜色 关于智能指针! 中国最差程序员和软件公司。 MFC动态生成控件并放于子容器group box, 如何为其设置处理事件? 问的问题很愚蠢,可是还得问,关于内存不能"written" 请各位能否推荐vc从入门到精通的一些书
#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