#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 Load_image alias "Load_image" (byval Namevhod as String,ByVal ColorBack As Integer) as HBITMAP Export
	DIM AS PVOID PTR GPIMAGE_01
	Dim hhbitmap As HBITMAP
	Var blen = (Len(Namevhod)*2)+2
	Dim As WString Ptr wbuf
	wbuf  = Allocate( blen )
	MultiByteToWideChar(CP_ACP, 0, StrPtr(Namevhod), -1, wbuf, blen)
	IF (GDIPLOADIMAGEFROMFILE( *wbuf, Cast(Any Ptr,@GPIMAGE_01)) <> 0) THEN
		PRINT "FAIL"
	End If
	DeAllocate(wbuf)
	If LOBYTE(LOWORD(GetVersion)) <6 Then
		DIM AS PVOID PTR GPIMAGE_02,GpGraphics
		Dim As Integer w,h
		GdipGetImageWidth(Cast(Any Ptr,GPIMAGE_01),@w)
		GdipGetImageHeight(Cast(Any Ptr,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),ColorBack or &hff000000)
		GdipDrawImageRectI(Cast(Any Ptr,GpGraphics),Cast(Any Ptr,GPIMAGE_01),0,0,w,h)
		GdipCreateHBITMAPFromBitmap(Cast(Any Ptr,GPIMAGE_02),@hhbitmap,ColorBack or &hff000000)
		If GPIMAGE_02 <> 0 Then GdipDisposeImage(Cast(Any Ptr,GPIMAGE_02))
		If GpGraphics <> 0 Then GdipDeleteGraphics(Cast(Any Ptr,GpGraphics))
	Else
		GdipCreateHBITMAPFromBitmap(Cast(Any Ptr,GPIMAGE_01) ,@hhBitmap,ColorBack or &hff000000)
	EndIf
	GdipDisposeImage(Cast(Any Ptr,GPIMAGE_01))
	Return hhbitmap
end Function


