;fast hack by UEZ
#include <GuiConstantsEx.au3>
#include <GDIPlus.au3>
#include <ScreenCapture.au3>

Opt('MustDeclareVars', 1)

_Main()

Func _Main()
    Local $hGUI1, $hGUI2, $hGUI3, $hImage, $hGraphic1, $hGraphic2, $hGraphic3, $sCLSID
	Local $bitmap1, $bitmap2, $bitmap3, $image1, $image2, $image3
	Local $tData, $tParams, $pParams, $pData

    ; Capture top left corner of the screen
    _ScreenCapture_Capture (@MyDocumentsDir & "\GDIPlus_Image.jpg", 0, 0, 400, 300)

    ; Create a GUI for the original image
    $hGUI1 = GUICreate("Original", 400, 300, 0, 0)
    GUISetState()

    ; Create a GUI for the scaled up image
    $hGUI2 = GUICreate("Scaled Up", 800, 600, 0, 350)
    GUISetState()

	; Create a GUI for the scaled down image
    $hGUI3 = GUICreate("Scaled Down", 200, 150, 820, 400)
    GUISetState()

    ; Initialize GDI+ library and load image
    _GDIPlus_Startup ()
    $hImage = _GDIPlus_ImageLoadFromFile (@MyDocumentsDir & "\GDIPlus_Image.jpg")

	$sCLSID = _GDIPlus_EncodersGetCLSID ("JPG")

	; Draw original image
    $hGraphic1 = _GDIPlus_GraphicsCreateFromHWND ($hGUI1)
	$bitmap1 = _GDIPlus_BitmapCreateFromGraphics(400, 300, $hGraphic1)
	$image1 = _GDIPlus_ImageGetGraphicsContext($bitmap1)
	_GDIPlus_GraphicsDrawImageRect($image1, $hImage, 0, 0, 400, 300)
	_GDIPlus_GraphicsDrawImageRect($hGraphic1, $bitmap1, 0, 0, 400, 300)
	_GDIPlus_ImageSaveToFileEx($bitmap1, @ScriptDir & "\GDIPlus_Image1.jpg", $sCLSID)
	_WinAPI_DeleteObject($bitmap1)
	_GDIPlus_GraphicsDispose($image1)

	; Draw 2x scaled up image and save with lower jpg quality
    $hGraphic2 = _GDIPlus_GraphicsCreateFromHWND ($hGUI2)
	$bitmap2 = _GDIPlus_BitmapCreateFromGraphics(800, 600, $hGraphic2)
	$image2 = _GDIPlus_ImageGetGraphicsContext($bitmap2)
    _GDIPlus_GraphicsDrawImageRectRect ($image2, $hImage, 0, 0, 400, 300, 0, 0, 800, 600)
	_GDIPlus_GraphicsDrawImageRect($hGraphic2, $bitmap2, 0, 0, 800, 600)
	$tParams = _GDIPlus_ParamInit (1)
	$tData = DllStructCreate("int Quality")
    DllStructSetData($tData, "Quality", 10) ;quality 0-100
	$pData = DllStructGetPtr($tData)
    _GDIPlus_ParamAdd($tParams, $GDIP_EPGQUALITY, 1, $GDIP_EPTLONG, $pData)
	$pParams = DllStructGetPtr($tParams)
	_GDIPlus_ImageSaveToFileEx($bitmap2, @ScriptDir & "\GDIPlus_Image2.jpg", $sCLSID, $pParams)
	_WinAPI_DeleteObject($bitmap2)
	_GDIPlus_GraphicsDispose($image2)
	$tData = 0

	; Draw 2x scaled down image
    $hGraphic3 = _GDIPlus_GraphicsCreateFromHWND ($hGUI3)
	$bitmap3 = _GDIPlus_BitmapCreateFromGraphics(200, 150, $hGraphic3)
	$image3 = _GDIPlus_ImageGetGraphicsContext($bitmap3)
    _GDIPlus_GraphicsDrawImageRectRect ($image3, $hImage, 0, 0, 400, 300, 0, 0, 200, 150)
	_GDIPlus_GraphicsDrawImageRect($hGraphic3, $bitmap3, 0, 0, 200, 150)
	_GDIPlus_ImageSaveToFileEx($bitmap3, @ScriptDir & "\GDIPlus_Image3.jpg", $sCLSID)
	_WinAPI_DeleteObject($bitmap3)
	_GDIPlus_GraphicsDispose($image3)

    ; Release resources
    _GDIPlus_GraphicsDispose ($hGraphic1)
    _GDIPlus_GraphicsDispose ($hGraphic2)
	_GDIPlus_GraphicsDispose ($hGraphic3)
    _GDIPlus_ImageDispose ($hImage)
    _GDIPlus_Shutdown ()

    ; Clean up screen shot file
    FileDelete(@MyDocumentsDir & "\GDIPlus_Image.jpg")

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

	Exit

EndFunc   ;==>_Main