The GDI+

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

Downloads

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



Comments

  • NABGU jPc tnMF

    Posted by MFCNYoNRux on 11/13/2012 06:30pm

    buy soma online carisoprodol can you snort - carisoprodol drug interactions

    Reply
  • Goal

    Posted by snareenactina on 11/13/2012 09:17am

    Build Bulk Cargo Handling Unit II-39 zelmenis The Finnish inventor's IndoorAtlas software uses magnetic field data to identify smartphone users' locations schmidt angiograms peakabove powerfulge admissible

    Reply
  • New one

    Posted by snareenactina on 11/06/2012 04:40am

    pewclimate French literature reflects the nation’s multi-hued culture and political dynamism. Several literary movements like Dadaism, Surrealism, and Existentialism have been started and nurtured in France. Since the late 19th century, the nation has also come to be known as a sort of focal point for modern art, cinema, fashion, and cuisine. Cocteau, Dumont, and Godard are some of its celebrated film-makers, while Pierre Cardin, Chanel, Givenchy, and Louis Vuitton are iconic names in the contemporary world of fashion. Europe has only one advantage over the US and that is its ability to spend close to nothing on a military budget because the United States will defend Europe under any opposing threat. Europe’s very existence depends on US supremacy. If the US decides to become a socialist state like Europe or if China calls in our debts, China will be in position to become the next superpower. Evidence of this is the German prime minister being opposed to “Obama spending”. The real question is, does anybody here believe China, with a poor track-record of preserving human rights, will come to defend Europe from the Middle East when the US can no longer financially provide military aid? I think not. Try zooming out for a broader look. forerunner Growth and protectionism 157 suggests Some articles that match your query: scotlands Cranky, the New York Times editorial came out and rallied around Obama??? Wow, more breaking news from the Associated Press: The Pope is Catholic and the Chicago Cubs will go 112 years without winning the world series. I mean seriously Cranky. judiciaries Like the poster above me I'd like to thank you for another one of your generally excellent and insightful comments on the economy. Over the past couple of years they have probably been amongst the most accurate forecasts out there. beetles The Moitor highlights that while unemployment continues to rise, longer term propsecxts give cause fo optimism as a result of a number of major development projects being taken forward. exclusivists Source: mundane For some time now, blogs and op-eds have been circulating a common myth about ‘great recession’ hiring. Namely, high unemployment is derived from a mismatch of job applicant skills versus job position skill requirements. And the absolutely true answer is: Chronic high unemployment is definitely NOT a supply side issue.

    Reply
  • 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?

    Reply
  • Problem getting GDI+ to work using DirectDraw & C++Builder

    Posted by Legacy on 01/28/2004 12:00am

    Originally posted by: Megan_G

    Hi, 
    
    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;

    lpSurface->GetDC(&hdc);
    Gdiplus::Graphics graphics(hdc);
    graphics.TranslateTransfor(SurfaceCenter,SurfaceCenter);
    graphics.RotateTransform(45.0f);
    lpSurface->ReleaseDC(hdc);

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

    Reply
  • 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?

    Reply
  • 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?

    Reply
  • 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?

    Reply
  • Alpha blending of an EMF Image

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

    Originally posted by: khaldoun

    Hi
    
    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,
    0.0f,1.0f,0.0f,0.0f,0.0f,
    0.0f,0.0f,1.0f,0.0f,0.0f,
    0.0f,0.0f,0.0f,float(125.0f/255.0f),0.0f,
    0.0f,0.0f,0.0f,0.0f,1.0f,};
    ImageAttributes imageAtt;
    //imageAtt.ClearColorMatrix();
    imageAtt.SetColorMatrix(&colorMatrix,ColorMatrixFlagsDefault,\
    ColorAdjustTypeBitmap);
    imageAtt.SetColorMatrix(&colorMatrix,ColorMatrixFlagsDefault,\
    ColorAdjustTypePen);
    imageAtt.SetColorMatrix(&colorMatrix,ColorMatrixFlagsDefault,\
    ColorAdjustTypeBrush);
    imageAtt.SetColorMatrix(&colorMatrix,ColorMatrixFlagsDefault,\
    ColorAdjustTypeText);

    RectF destRect(0.0f, 0.0f,
    (REAL)m_pPosition->GetWidth(),
    (REAL)m_pPosition->GetHeight());


    pGraphics->DrawImage(pImage,destRect,\
    0.0f,0.0f,pImage->GetWidth(), \
    pImage->GetHeight(),UnitPixel,&imageAtt,NULL,NULL);

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

    Reply
  • 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

    Ouioui

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

Top White Papers and Webcasts

  • With JRebel, developers get to see their code changes immediately, fine-tune their code with incremental changes, debug, explore and deploy their code with ease (both locally and remotely), and ultimately spend more time coding instead of waiting for the dreaded application redeploy to finish. Every time a developer tests a code change it takes minutes to build and deploy the application. JRebel keeps the app server running at all times, so testing is instantaneous and interactive.

  • When it comes to desktops – physical or virtual – it's all about the applications. Cloud-hosted virtual desktops are growing fast because you get local data center-class security and 24x7 access with the complete personalization and flexibility of your own desktop. Organizations make five common mistakes when it comes to planning and implementing their application management strategy. This eBook tells you what they are and how to avoid them, and offers real-life case studies on customers who didn't let …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds