views:

1190

answers:

2
+2  Q: 

Using GDI+ Bitmap

Hi

I am using GDI+ Bitmap class to convert an IStream to HBITMAP. I have included the gliplus lib file in the Linker inputs and also have the dll in the build path. But using the statement

Bitmap bm(lpStream,FALSE);

gives me an error C2065: 'Bitmap' : undeclared identifier

Can someone please tell me what I am doing wrong here.

Thanks.

Edit
I have already included the appropriate headers in my implementation (gdiplus.h) And I can view the definition of Bitmap by selecting the "Go to definition" option in the context menu.

+2  A: 

You also need to include the relevant header file. At a guess, it would probably have a name like "Bitmap.h" or "gdi+.h".

There is some more detail on the Bitmap class here. The correct header file is "gdiplus.h". In short:

#include "gdiplus.h"

Constructor Information
Stock Implementation  gdiplus.dll
Header    Declared in Gdiplusheaders.h, include gdiplus.h
Import library    gdiplus.lib
Minimum availability  GDI+ 1.0
Minimum operating systems  Windows 98/Me, Windows XP, Windows 2000,

Windows NT 4.0 SP6

In the table in MSDN, where it says "Header", this tells you the name of the header file you need to include. The "Import Library" you have already covered. Had you missed that, you would have gotten a link error.

EDIT: In this article on getting started with GDI+, it looks like there is a namespace "Gdiplus" that you need to specify. Either use "using namespace Gdiplus" or specify the namespace explicitly.

#include <windows.h>
#include <gdiplus.h>
using namespace Gdiplus;

VOID OnPaint(HDC hdc)
{
   Graphics graphics(hdc);
   Pen      pen(Color(255, 0, 0, 255));
   graphics.DrawLine(&pen, 0, 0, 200, 100);
}
1800 INFORMATION
Hi. I have already included gdiplus.h in the class. Visual Studio opens up the definition of the class too so I know headers are recognized. But it still does not compile.
lostInTransit
Did you include it in your source file or in the precompiled header file (stdafx.h)? If the latter, you'll need to rebuild the precompiled header.
1800 INFORMATION
i did both to be on the safer side. and i did a clean build
lostInTransit
You should check for the existance of a namespace or maybe there is a predefined preprocessor symbol that needs to be defined?
1800 INFORMATION
There is a namespace called "Gdiplus"
1800 INFORMATION
I am working in vc++. I have included the header file though.
lostInTransit
+2  A: 

In addition to the namespace issue, using Gdiplus also requires that the library is initialized before it is used:

ULONG_PTR gdiplusToken;
GdiplusStartupInput startupInput;
GdiplusStartup(&gdiplusToken, &startupInput, 0);

You will need to hold on to the token until you are done using Gdiplus, then release it:

GdiplusShutdown(gdiplusToken);

If the library is not initialized, Gdiplus operations will fail with the error GdiplusNotInitialized.

Chris Ostler