#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_imageA(byval Namevhod as String) as Any Ptr Export
	DIM GPIMAGE_01 AS GPBITMAP PTR
	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(GpImage ptr Ptr,@GPIMAGE_01)) <> 0) THEN
		PRINT "FAIL"
	End If
	DeAllocate(wbuf)
	Return GPIMAGE_01
end Function
Function Copy_imageA(byval GpImage as Any Ptr) as Any Ptr Export
	If GpImage=0 Then Return 0
	DIM GPIMAGE_01 AS Any PTR
	GdipCloneImage(GpImage,@GPIMAGE_01)
	Return GPIMAGE_01
end Function
Function Grab_imageA(byval GpImage as Any Ptr,ByVal x As Single=0, ByVal y As Single=0, Byref width_ As Single=0, ByRef height_ As Single=0) as Any Ptr Export
	If GpImage=0 Then Return 0
	DIM GPIMAGE_01 AS Any Ptr
	If width_=0 Then
		GdipGetImageWidth(GPImage,Cast(UINT Ptr,@width_))
	EndIf
	If height_=0 Then
		GdipGetImageHeight(GPImage, Cast(UINT Ptr,@height_))
	EndIf
	GdipCloneBitmapArea(x,y,width_,height_,PixelFormat32bppARGB,GpImage,@GPIMAGE_01)
	Return GPIMAGE_01
end Function
Sub Resize_imageA(ByRef GpImage as Any Ptr,ByRef width_ As Single=0, ByRef height_ As Single=0)  Export
	If GpImage=0 Then Exit Sub
	DIM GPIMAGE_01 AS Any Ptr
	If width_=0 Then
		GdipGetImageWidth(GPImage,Cast(UINT Ptr,@width_))
	EndIf
	If height_=0 Then
		GdipGetImageHeight(GPImage, Cast(UINT Ptr,@height_))
	EndIf
	GPIMAGE_01=Create_ImageA(width_,height_)
	ImageStartDrawA(GPIMAGE_01,1,&h00000000)
	ImageDrawA(GpImage,0,0,width_,height_)
	StopDrawA()
	GdipDisposeImage(GpImage)
	GpImage=GPIMAGE_01
End Sub
Function Image_WidthA(byval GpImage as Any Ptr) as Integer Export
	Dim As Integer w
	GdipGetImageWidth(GPImage,@w)
	Return w
end Function
Function Image_HeightA(byval GpImage as Any Ptr) as Integer Export
	Dim As Integer h
	GdipGetImageHeight(GPImage,@h)
	Return h
end Function
