The GDI+
Posted
by Leandro Gustavo Biss Becker
on September 20th, 2001
I have found that the Microsft GDI+ can do many cool things for you. Previously you had to find code or write your own code to do the same things. One of these things is the ability to load or save the following types of images:
- BMP
- DIB
- RLE
- GIF
- JPEG
- EMF
- TIFF
- PNG
These can be loaded with just a few lines of code like this:
#include <Gdiplus.h> using namespace Gdiplus; #pragma comment(lib, "gdiplus.lib") Image Im(L"c:\\fig.jpg", FALSE); CLSID GifCodec; GetCodecClsid(L"image/gif", &GifCodec); Im.Save(L"c:\\fig.gif", &GifCodec, NULL);
Here is the code to GetCodecClsid
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
All help about GDI+ can be found at: http://msdn.microsoft.com/library/default.asp
Downloads
Here is the library, headers and the dll to build the samples gdiplus.zip (900K):

Comments
Problem with linking (GDI+ + CBuilder 5)
Posted by Legacy on 02/22/2004 12:00amOriginally posted by: dbf
Hello! My gdi program compiles quite good, but it after it it is linking error.
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
#define STRICT
#include <Gdiplus.h>
using std::min;
using std::max;
using namespace Gdiplus;
#pragma comment(lib, "gdiplus.lib")
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
CLSID pngClsid;
//GetEncoderClsid(L"image/png", &pngClsid);
//image.Save(L"Mosaic2.png", &pngClsid, NULL);
GdiplusShutdown( gdiplusToken );
}
//---------------------------------------------------------------------------
ReplyThe error is "Unresolved external call GdiplusStartupInput
Unresolved external call GdiplusShutdown " What should I do?
Problem getting GDI+ to work using DirectDraw & C++Builder
Posted by Legacy on 01/28/2004 12:00amOriginally posted by: Megan_G
ReplyHow to load a HICON or Bitmap object in Image handle?
Posted by Legacy on 11/21/2003 12:00amOriginally posted by: Yan Lee
How to load a HICON or Bitmap object in Image handle?
ReplyHow to load a HICON or Bitmap object in Image handle?
Posted by Legacy on 11/21/2003 12:00amOriginally posted by: Yan Lee
How to load a HICON or Bitmap object in Image handle?
ReplyHow to load a HICON or Bitmap object in Image handle?
Posted by Legacy on 11/21/2003 12:00amOriginally posted by: Wang Yan
How to load a HICON or Bitmap object in Image handle?
ReplyAlpha blending of an EMF Image
Posted by Legacy on 11/20/2003 12:00amOriginally posted by: khaldoun
ReplyGDIplus.lib linker error with c++ builder 6
Posted by Legacy on 11/19/2003 12:00amOriginally posted by: ouioui
I make a small app to rotate a jpeg image with c++ builder but i can't compile it. I get this error :
[Linker Error] 'C:TEST_GDI\GDIPLUS.LIB' contains invalid OMF record, type 0x21 (possibly COFF)
Thanks for help
Ouioui
ReplyPolyPolygon in GDI+ ?
Posted by Legacy on 08/26/2003 12:00amOriginally posted by: Sangkil Choi
Hi all,
what is the counterpart for GDI's function PolyPolygon in GDI+ such as Graphics::FillPolyPolygon()?
Thanks in advance,
ReplyCan't compile simple Hello World with GDI+ What really a ...t going on?
Posted by Legacy on 08/20/2003 12:00amOriginally posted by: @AM
Created default VC++ 6.0 Hello world no MFC app.
Add to StdAfx.h after windows.h
#include <gdiplus.h>
using namespace Gdiplus
Directories changed to MSSDK\include, MSSDK\lib
gdiplus.lib added
gdi initialized and so on. Just stupidly took code from MSDN gdi+ example...
Still get:
c:\sdk\microsoft sdk\include\gdiplusimaging.h(67) : error C2501: 'MIDL_INTERFACE' : missing storage-class or type specifiers
c:\sdk\microsoft sdk\include\gdiplusimaging.h(67) : error C2440: 'initializing' : cannot convert from 'char [37]' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
and so on
If anybody can help - I'll appreciate
ReplyCheers
Facing Exception
Posted by Legacy on 08/06/2003 12:00amOriginally posted by: umar
ReplyLoading, Please Wait ...