NO

Author Topic: GDI+ flat  (Read 1424 times)

Offline iwrbc

  • Member
  • *
  • Posts: 16
GDI+ flat
« 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. 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.
Any help is appreciated.

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Re: GDI+ flat
« Reply #1 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
May the source be with you

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2096
Re: GDI+ flat
« Reply #2 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.
Then download the manual here.
Then try the attached example that shows how to save an image (is the sample in the thread you showed).
« Last Edit: December 15, 2023, 05:44:23 PM by frankie »
It is better to be hated for what you are than to be loved for what you are not. - Andre Gide

Offline iwrbc

  • Member
  • *
  • Posts: 16
Re: GDI+ flat
« Reply #3 on: December 15, 2023, 04:03:57 PM »
Great, thanks for fast reply, I got it working.