The GDI+


Application Security Testing: An Integral Part of DevOps

Environment: [VC6 SP4, NT4 SP3, W2k, Win 9x]

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


Here is the library, headers and the dll to build the samples gdiplus.zip (900K):


  • Problem with linking (GDI+ + CBuilder 5)

    Posted by Legacy on 02/22/2004 12:00am

    Originally 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 );

    The 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:00am

    Originally posted by: Megan_G

    I am trying to use GDI+ for the first time in C++Builder.
    I have a DirectDrawSurface7 that I want to manipulate using GDI+. I created an HDC object that points to the surface and used it to make a graphics object. Everything compiles and links fine. I call the rotate and translate functions and my surface comes back in the same orientation as it would be if I had never called these. Here is the code.

    HDC hdc;
    HRESULT hr;

    Gdiplus::Graphics graphics(hdc);

    Has anyone run into a problem like this? Have any ideas?

  • How to load a HICON or Bitmap object in Image handle?

    Posted by Legacy on 11/21/2003 12:00am

    Originally posted by: Wang Yan

    How to load a HICON or Bitmap object in Image handle?

  • How to load a HICON or Bitmap object in Image handle?

    Posted by Legacy on 11/21/2003 12:00am

    Originally posted by: Yan Lee

    How to load a HICON or Bitmap object in Image handle?

  • How to load a HICON or Bitmap object in Image handle?

    Posted by Legacy on 11/21/2003 12:00am

    Originally posted by: Yan Lee

    How to load a HICON or Bitmap object in Image handle?

  • Alpha blending of an EMF Image

    Posted by Legacy on 11/20/2003 12:00am

    Originally posted by: khaldoun

    I want to set the alpha blending of an emf,
    I want it to be transparent.
    my code is the folowing :
    pImage = ::new Image(strDstFileName);

    ColorMatrix colorMatrix = {1.0f,0.0f,0.0f,0.0f,0.0f,
    ImageAttributes imageAtt;

    RectF destRect(0.0f, 0.0f,

    0.0f,0.0f,pImage->GetWidth(), \

    When my image is a BMP or JPEG, it works very well,
    but when I pass an EMF file it draw nothing???
    any help

  • GDIplus.lib linker error with c++ builder 6

    Posted by Legacy on 11/19/2003 12:00am

    Originally 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


  • PolyPolygon in GDI+ ?

    Posted by Legacy on 08/26/2003 12:00am

    Originally posted by: Sangkil Choi

    Hi all,
    what is the counterpart for GDI's function PolyPolygon in GDI+ such as Graphics::FillPolyPolygon()?

    Thanks in advance,

  • Can't compile simple Hello World with GDI+ What really a ...t going on?

    Posted by Legacy on 08/20/2003 12:00am

    Originally 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

  • Facing Exception

    Posted by Legacy on 08/06/2003 12:00am

    Originally posted by: umar

    I am facing exception on this line ...
    Image Im(L"c:\\fig.jpg", FALSE);

    would u plz guide me where is the problemmm

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • As all sorts of data becomes available for storage, analysis and retrieval - so called 'Big Data' - there are potentially huge benefits, but equally huge challenges...
  • The agile organization needs knowledge to act on, quickly and effectively. Though many organizations are clamouring for "Big Data", not nearly as many know what to do with it...
  • Cloud-based integration solutions can be confusing. Adding to the confusion are the multiple ways IT departments can deliver such integration...

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.