#include Once "window9.bi"

Sub Rotateandscaleimagea(Byval GpbitmapSource As Any Ptr, Byref hbmpDest As HBITMAP,_
Byval X As Integer, Byval Y As Integer,Byval Xr As Integer,Byval Yr As Integer,_
Byval angle As Single,Byval Xscale As Single=0,Byval Yscale As Single=0,_
Byval iColor As Integer=0,Byval BGbitmap As Any Ptr=0)
	
	Var cr = Imagestartdrawa(hbmpDest)
	
	If BGbitmap = 0 Then
		
		Dim As Double  rBG , gBG , bBG , aBG
		
		aBG = Cast(Ushort,((iColor And &hFF000000) Shr 16) Or (iColor And &hFF000000) Shr 24)/&hFFFF
		
		rBG = Cast(Ushort,((iColor And &h00FF0000) Shr 8) Or (iColor And &h00FF0000) Shr 16)/&hFFFF
		
		gBG = Cast(Ushort,(iColor And &h0000FF00) Or (iColor And &h0000FF00) Shr 8)/&hFFFF
		
		bBG = Cast(Ushort,((iColor And &h000000FF)Shl 8) Or (iColor And &h000000FF))/&hFFFF
		
		cairo_set_source_rgba(cr , bBG , gBG , rBG , aBG)
		
		cairo_paint (cr)
		
	Else
		
		Imagedrawa(BGbitmap ,  0 , 0 )
		
	Endif
	
	cairo_translate(cr, X, Y )
	
	If Xscale<>0 Orelse Yscale<>0 Then
		
		cairo_scale(cr , Xscale , Yscale)
		
	Endif
	
	cairo_rotate(cr , angle)
	
	Imagedrawa(GpbitmapSource , -Xr , -Yr )
	
	Stopdrawa
	
End Sub