Pelles C forum

C language => Windows questions => Topic started by: iwrbc on December 15, 2023, 12:19:36 PM

Title: GDI+ flat
Post by: iwrbc on December 15, 2023, 12:19:36 PM
Hi,
I am trying to reproduce some of the code in this thread https://forum.pellesc.de/index.php?topic=7146.0 (https://forum.pellesc.de/index.php?topic=7146.0). I am confused by this block of code:
Code: [Select]
GpBitmap *bitmap = NULL;
GdipCreateBitmapFromScan0(100, 100, 0, PixelFormat32bppARGB, NULL, &bitmap); // create a bitmap object with specified width/height/color
GpGraphics *graph;
GdipGetImageGraphicsContext(bitmap, &graph); // create a graphic object via bitmap object
Because if I copy that to my program, the last line of this block gives a compiler error:
error #2140: Type error in argument 1 to 'GdipGetImageGraphicsContext'; expected 'GpImage (aka (incomplete) struct tagGpImage) *' but found 'GpBitmap (aka (incomplete) struct tagGpBitmap) *'. Which is consistent with the contents of fGdiPlusFlat.h

Am I doing something wrong? Or is there another way to create a graphic object from a bitmap?
BTW My ultimate goal is to create, display and save a bitmap as a .png-file, like in this post https://stackoverflow.com/questions/39551863/creating-gdi-bitmaps-in-memory-and-then-saving-as-png (https://stackoverflow.com/questions/39551863/creating-gdi-bitmaps-in-memory-and-then-saving-as-png).
Any help is appreciated.
Title: Re: GDI+ flat
Post by: TimoVJL on December 15, 2023, 02:58:30 PM
Perhaps have to cast it , as GpImage is for common usage
Code: [Select]
GdipGetImageGraphicsContext((GpImage*)bitmap, &graph); // create a graphic object via bitmap object
C++ (Cpp) GdipGetImageGraphicsContext Examples (https://cpp.hotexamples.com/examples/-/-/GdipGetImageGraphicsContext/cpp-gdipgetimagegraphicscontext-function-examples.html)
Title: Re: GDI+ flat
Post by: frankie on December 15, 2023, 03:48:07 PM
First of all be sure to have the last version of my fGdiPlusFlat.h header file that you can download from here (https://github.com/Frankie-PellesC/fSDK/blob/master/Include/fGdiPlusFlat.h).
Then download the manual here (https://github.com/Frankie-PellesC/fSDK/blob/master/GDI%2B%20Made%20flat%20-%20part%201.pdf).
Then try the attached example that shows how to save an image (is the sample in the thread you showed).
Title: Re: GDI+ flat
Post by: iwrbc on December 15, 2023, 04:03:57 PM
Great, thanks for fast reply, I got it working.