#include once "window9.bi"

Using GDIPLUS

Dim shared ULONG_PTR_01 AS ULONG_PTR
DIM GDIPLUSSTARTUPINPUT_01 AS GDIPLUSSTARTUPINPUT
GDIPLUSSTARTUPINPUT_01.GdiplusVersion = 1
IF (GDIPLUSSTARTUP(@ULONG_PTR_01, @GDIPLUSSTARTUPINPUT_01, NULL) <> 0) THEN
	PRINT "FAIL"
EndIf
Function CreateHBitmapFromGpBitmap(ByVal GPIMAGE_01 As Any Ptr,ByVal iBackColor As Integer=&hf0f0f0) As HBITMAP Export
	Dim bmp As HBITMAP
	Dim As Long iColorFill = ((iBackColor And &h000000ff) Shl 16) Or (iBackColor And &h0000ff00) Or ((iBackColor And &h00ff0000) Shr 16) Or &hFF000000
	If LoByte(LOWORD(GetVersion)) <6 Then
		DIM AS PVOID PTR GPIMAGE_02,GpGraphics
		Dim As long w,h
		GdipGetImageWidth(GPIMAGE_01,@w)
		GdipGetImageHeight(GPIMAGE_01,@h)
		GdipCreateBitmapFromScan0(w, h, 0, PixelFormat32bppARGB, NULL, Cast(Any Ptr,@GPIMAGE_02))
		GdipGetImageGraphicsContext(Cast(Any Ptr,GPIMAGE_02),Cast(Any Ptr,@GpGraphics))
		GdipGraphicsClear(Cast(Any Ptr,GpGraphics),iColorFill)
		GdipDrawImageRectI(Cast(Any Ptr,GpGraphics),GPIMAGE_01,0,0,w,h)
		GdipCreateHBITMAPFromBitmap(Cast(Any Ptr,GPIMAGE_02),@bmp,iColorFill)
		If GPIMAGE_02 <> 0 Then GdipDisposeImage(Cast(Any Ptr,GPIMAGE_02))
		If GpGraphics <> 0 Then GdipDeleteGraphics(Cast(Any Ptr,GpGraphics))
	Else
		GdipCreateHBITMAPFromBitmap(GPIMAGE_01,@bmp,iColorFill)
	EndIf
	Return bmp
End Function
Function CreateGPBitmapFromHBitmap(ByVal HBitmap As HBITMAP) As Any Ptr Export
	Dim GpBitmap As Any Ptr
	GdipCreateBitmapFromHBITMAP(hBitmap, NULL, @GpBitmap)
	Return GpBitmap
End Function
Sub Free_imageA(ByVal GPBitmap As Any Ptr  ) Export
	GdipDisposeImage(GPbitmap)
End Sub
