• Welcome to Jose's Read Only Forum 2023.
 

GDIplus images and bitmaps

Started by Chris Holbrook, March 29, 2010, 11:44:32 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Chris Holbrook

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:
l = GdipSaveImageToFile (byval himage, byval ucode$(savefilename + $nul), EncoderCLSID, byval %NULL)       

this doesn't work, in the sense that it creates a black image:
            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)

         

José Roca

 
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.

Patrice Terrier

#2
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.

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

José Roca

 
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.

Patrice Terrier

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

Chris Holbrook

Thank you, Gentlemen! Another evening of exploration ahead.

Jürgen Huhn

#6
Quote from: Patrice Terrier 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).

...



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
.¸.•'´¯)¸.•'´¯)¸.•'´¯)¸.•'´¯)
¤ª"˜¨¨¯¯¨¨˜"ª¤....¤ ª"˜¨