Author Topic: GDIplus images and bitmaps  (Read 15672 times)

0 Members and 1 Guest are viewing this topic.

Offline Chris Holbrook

  • Newbie
  • *
  • Posts: 44
  • User-Rate: +5/-2
GDIplus images and bitmaps
« on: March 29, 2010, 11:44:32 PM »
Hello GDIplus experts!

Are images and bitmaps always the same? ISTR reading something to that effect in these forums long ago. But MSDN says that bitmap inherits from the image class, not that they are the same.

I was thinking about this when debugging the following code, in which an image is successfully written to a file, and a bitmap isn't.

However, it is just as likely that I have made a coding blunder.

Assistance would be very welcome.

this works:
Code: [Select]
l = GdipSaveImageToFile (byval himage, byval ucode$(savefilename + $nul), EncoderCLSID, byval %NULL)       

this doesn't work, in the sense that it creates a black image:
Code: [Select]
            hdc = getdc(cb.hndl)
            l = GdipCreatefromHDC ( hDC, pGraphics)
            if l then
                sGDIPfn = "GDIPCreatefromHDC": gosub gdiperror
            else
                l = GdipDrawImageRectI(pGraphics, himage, ofsX, ofsY, tX, tY)
                if l then sGDIPfn = "GdipDrawImageRectI": gosub gdiperror
            end if
            getclientrect cb.hndl, r
            w = r.nright  - r.nleft
            h = r.nbottom - r.ntop
            ? str$(w)+str$(h) + "  " + str$(pgraphics) + str$(pbitmap)
            l = GdipCreateBitmapFromGraphics ( byval w, byval h, byval pgraphics, pbitmap)
            if l then sGDIPfn = "GDIPCreateBitmapFromGraphics": gosub gdiperror
            '
            l = GdipSaveImageToFile (byval pbitmap, byval ucode$(savefilename + $nul), EncoderCLSID, byval %NULL)
         

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
  • User-Rate: +204/-0
Re: GDIplus images and bitmaps
« Reply #1 on: March 30, 2010, 03:37:33 AM »
 
Well, GdipCreateBitmapFromGraphics creates a new, blank, usually solid black bitmap in memory which can be used with GDI+, not a clipped copy of the image.

Offline Patrice Terrier

  • ROMs
  • Hero Member
  • *****
  • Posts: 936
  • User-Rate: +62/-1
    • www.zapsolution.com
Re: GDIplus images and bitmaps
« Reply #2 on: March 30, 2010, 09:36:34 AM »
GDI bitmap handle and a GDIPLUS image handle are not the same.


GDIPLUS has two flat API: GdipCreateBitmapFromHBITMAP and GdipCreateHBITMAPFromBitmap, that shoud do the conversion, but indeed they do not work with 32-bit bitmap when using an alpha channel.

Please note the word "HBITMAP" with ucase letters that refers to a GDI bitmap handle and the word "bitmap" in lowercase for GDIPLUS handle, just to make things harder for the non initiated ;)


Some graphic toolkit provide specific functions for that purpose, for example in GDImage:

ZI_CreateBitmapFromImage
Convert a GDIPLUS image handle into a GDI32 bitmap handle.

FUNCTION ZI_CreateBitmapFromImage ( _
BYVAL hImage AS LONG _   ' The GDIPLUS image handle to convert from.
) AS LONG

Return:
A valid GDI32 bitmap handle (do not confuse GDI bitmap handle and GDI+ Image handle).

Important:
You must delete the GDIPLUS image handle if you don't need it anymore.


ZI_CreateImageFromBitmap  
Convert a GDI32 bitmap handle into a GDIPLUS image handle.

FUNCTION ZI_CreateImageFromBitmap ( _
BYVAL hBmp AS LONG _   ' The GDI32 bitmap handle to convert from.
) AS LONG

Return:
A valid GDIPLUS image handle (do not confuse GDI bitmap handle and GDI+ Image handle).

Important:
You must delete the GDI32 bitmap handle if you don't need it anymore.




Note: to avoid the confusion, i am using myself the word "image" for a GDIPLUS handle, and the word "bitmap" for a GDI handle.

...
« Last Edit: March 30, 2010, 09:39:52 AM by Patrice Terrier »
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
  • User-Rate: +204/-0
Re: GDIplus images and bitmaps
« Reply #3 on: March 30, 2010, 05:39:56 PM »
 
GDI bitmaps and GDI+ bitmaps aren't the same, but I think that Chris is talking about GDI+ bitmaps and GDI+ images, and these, as far as I know are the same. The MSDN documentation saying that bitmap inherits from the image class applies only to the C++ wrappers.

Offline Patrice Terrier

  • ROMs
  • Hero Member
  • *****
  • Posts: 936
  • User-Rate: +62/-1
    • www.zapsolution.com
Re: GDIplus images and bitmaps
« Reply #4 on: March 30, 2010, 06:54:52 PM »
Yes GDI+ bitmaps and GDI+ images are synonym, as long as they are using lowercase in the API name.
HBITMAP refers to a GDI bitmap.

And GdipCreateBitmapFromGdiDib is to deal with DIB (GDI, GDIPLUS, and OpenGL).

...
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Offline Chris Holbrook

  • Newbie
  • *
  • Posts: 44
  • User-Rate: +5/-2
Re: GDIplus images and bitmaps
« Reply #5 on: March 30, 2010, 09:35:51 PM »
Thank you, Gentlemen! Another evening of exploration ahead.

Offline Jürgen Huhn

  • Jr. Member
  • **
  • Posts: 61
  • User-Rate: +9/-3
Re: GDIplus images and bitmaps
« Reply #6 on: May 10, 2010, 01:21:35 AM »
Yes GDI+ bitmaps and GDI+ images are synonym, as long as they are using lowercase in the API name.
HBITMAP refers to a GDI bitmap.

And GdipCreateBitmapFromGdiDib is to deal with DIB (GDI, GDIPLUS, and OpenGL).

...



That`s the Point "we have to Deal"!

And to deal on Windows with Bitmaps, we need an "Object" wich is based on a Bitmap Handel or based on another Bitmap Objekt.

That`s why we have two Bitmaps!

The GDI bitmap and the Bitmap as an Objekt.

Windows use the "Windows Graphics Device Interface" wich Properties depends or based on the Hardware of the System or Computer for any bitmap.  
Eg.: Display,Printer,HardDisk ect., the Device.
 
That`s the "GDI bitmap". (Graphics Device Interface Bitmap)

And the other Bitmap is the Bitmap as an Object:

Bitmap object based on a handle to a Windows (GDI) bitmap              ->> GDI is the Windows Graphics Device Interface

Bitmap object based on a handle to a BITMAPINFO structure (DIB) bitmap ->> DIB is the Device Independent Bitmap

Bitmap object based on a handle to a Graphics object ->> (GDI+) bitmap or (GDI+) Image

Bitmap object based on a stream, on an ICONINFO structure and more...


This GDI+ Bitmap function`s handel or dealing with Bitmap Objects this way:
 

GdipCreateBitmapFromHBITMAP   Creates a Bitmap::Bitmap object based on a handle to a Windows (GDI) bitmap and a handle to a GDI palette

GdipCreateHBITMAPFromBitmap   The Bitmap::GetHBITMAP method creates a GDI bitmap from this Bitmap object.

GdipCreateBitmapFromGdiDib    Creates a Bitmap::Bitmap object based on a BITMAPINFO structure and an array of pixel data

GdipCreateBitmapFromGraphics  Creates a Bitmap::Bitmap object based on a Graphics object, a width, and a height.

and more ...

Windows GDI+ exposes a flat API that consists of about 600 functions and included are about 40 Bitmap functions, which are implemented in Gdiplus.dll of WindowsXP and higher.

I needed also a definition for the Names of Bitmap`s, this is my..

Regads
« Last Edit: May 10, 2010, 01:23:27 AM by Jürgen Huhn »
.¸.•’´¯)¸.•’´¯)¸.•’´¯)¸.•’´¯)
¤ª“˜¨¨¯¯¨¨˜“ª¤....¤ ª“˜¨