MSDN.WhiteKnight - Stack Overflow answers
Ответ на "Язык "C" конвертация bmp в jpeg"
Answer 854496
Например с помощью GDI+ Flat API:
#include <stdio.h> #include <tchar.h> #include <Windows.h> typedef struct _GdiplusStartupInput { UINT32 GdiplusVersion; // Must be 1 (or 2 for the Ex version) void* DebugEventCallback; // Ignored on free builds BOOL SuppressBackgroundThread; // FALSE unless you're prepared to call // the hook/unhook functions properly BOOL SuppressExternalCodecs; // FALSE unless you want GDI+ only to use // its internal image codecs. } GdiplusStartupInput; typedef struct _GdiplusStartupOutput { void* NotificationHook; void* NotificationUnhook; } GdiplusStartupOutput; int _tmain(int argc, _TCHAR* argv[]) { HANDLE g ; int (__stdcall *GdiplusStartup)(ULONG_PTR *,const GdiplusStartupInput *,GdiplusStartupOutput *); int (__stdcall *GdiplusShutdown)(ULONG_PTR *); int (__stdcall *GdipLoadImageFromFile)(WCHAR* filename, void **image); int (__stdcall *GdipSaveImageToFile) (void *image, WCHAR* filename, void* clsidEncoder, void* encoderParams); GdiplusStartupInput input = {1,0}; GdiplusStartupOutput output = {0}; ULONG_PTR gdiplusToken; CLSID encoderClsid ={0x557cf401,0x1a04,0x11d3,0x9a,0x73,0x00,0x00,0xf8,0x1e,0xf3,0x2e}; //image/jpeg void* pImage=NULL; int result; //загрузка указателей на функции g= LoadLibraryA("gdiplus.dll"); GdiplusStartup= (int (__stdcall *)(ULONG_PTR *,const GdiplusStartupInput *,GdiplusStartupOutput *))GetProcAddress((HMODULE)g,"GdiplusStartup"); GdiplusShutdown= (int (__stdcall *)(ULONG_PTR *))GetProcAddress((HMODULE)g,"GdiplusShutdown"); GdipLoadImageFromFile = (int (__stdcall *)(WCHAR* filename, void **image))GetProcAddress((HMODULE)g,"GdipLoadImageFromFile"); GdipSaveImageToFile = (int (__stdcall *) (void *image, WCHAR* filename, void* clsidEncoder, void* encoderParams))GetProcAddress((HMODULE)g,"GdipSaveImageToFile"); //инициализация GDI+ result = GdiplusStartup(&gdiplusToken,&input,&output); if(result != 0) {wprintf(L"GdiplusStartup failed: error %d\n",result);getchar();return 1;} //загрузка Image result = GdipLoadImageFromFile(L"d:\\image.bmp",&pImage); if(result != 0) {wprintf(L"GdipLoadImageFromFile failed: error %d\n",result);getchar();return 1;} //сохранение Image result = GdipSaveImageToFile(pImage,L"d:\\image.jpg",&encoderClsid,NULL); if(result != 0) {wprintf(L"GdipSaveImageToFile failed: error %d\n",result);getchar();return 1;} wprintf(L"Image saved successfully\n"); GdiplusShutdown(&gdiplusToken); getchar(); return 0; }
Content is retrieved from StackExchange API.
Auto-generated by ruso-archive tools.