征求tif转为bm的源代码 征求tif转为bm的源代码 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 #include <Stdio.h>#include <Objbase.h>#include <Windows.h>#include <Gdiplus.h>#include <GdiPlusEnums.h>using namespace Gdiplus;#pragma comment(lib,"gdiplus")// Helper functionsint 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 bmp file.\n if it works, it is written by masterz, otherwise I don't know who write it",argv[0]); if(argc!=3) { printf("usage:%s bmp_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/bmp", &codecClsid); encoderParameters.Count = 0; LPOLESTR bstr_src_img; LPOLESTR bstr_dst_bmp; AnsiToUnicode(argv[1],&bstr_dst_bmp); AnsiToUnicode(argv[2],&bstr_src_img); Image image(bstr_src_img); stat =image.Save(bstr_dst_bmp, &codecClsid, &encoderParameters); if(stat == Ok) { n_ret=0; wprintf(L"%s saved successfully.\n",bstr_dst_bmp); } else { n_ret=-2; wprintf(L"%d Attempt to save %s failed.\n", stat, bstr_dst_bmp); } CoTaskMemFree(bstr_dst_bmp); 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: img2bmp a.bmp b.gif datetime结构体的头文件是什么 求懂OPENCV的大神指明小弟怎么用OPENCV编写寻迹的程序 给高分啊。。。。。。。。 有个小问题,求高人指点 狂求<<监听与隐藏>>一书的电子版资料及带光盘源码 VC下的组框怎么做才能响应单击事件? 怎样通过hwnd控制窗体的控件 如何在属性面的标签上插入图标? 还是钩子在困扰我啊!!!!! 一个非常难的问题,难倒了我。 seesi兄,有个问题要请教。 高手指点,关于dll共享数据的问题! 有什么类是用来选择目录的呢?
#include <Objbase.h>
#include <Windows.h>
#include <Gdiplus.h>
#include <GdiPlusEnums.h>
using namespace Gdiplus;
#pragma comment(lib,"gdiplus")
// Helper functions
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 bmp file.\n if it works, it is written by masterz, otherwise I don't know who write it",argv[0]);
if(argc!=3)
{
printf("usage:%s bmp_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/bmp", &codecClsid);
encoderParameters.Count = 0;
LPOLESTR bstr_src_img;
LPOLESTR bstr_dst_bmp;
AnsiToUnicode(argv[1],&bstr_dst_bmp);
AnsiToUnicode(argv[2],&bstr_src_img);
Image image(bstr_src_img);
stat =image.Save(bstr_dst_bmp, &codecClsid, &encoderParameters);
if(stat == Ok)
{
n_ret=0;
wprintf(L"%s saved successfully.\n",bstr_dst_bmp);
}
else
{
n_ret=-2;
wprintf(L"%d Attempt to save %s failed.\n", stat, bstr_dst_bmp);
}
CoTaskMemFree(bstr_dst_bmp);
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: img2bmp a.bmp b.gif