#include Once "window9.bi"

Sub Rotateandscaleimage(Byval sourcehBmp As HBITMAP, 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 HBITMAP=0)
	
	Var cr = Imagestartdraw(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
		
		Imagedraw(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)
	
	Imagedraw(sourcehBmp , -Xr , -Yr )
	
	Stopdraw
	
End Sub