Sign in to follow this  
Followers 0
GodlessSinner

Save image after transform

4 posts in this topic

#include <GUIConstants.au3>
#include <ScreenCapture.au3>
#include <WinAPI.au3>

; Create GUI
$hWnd = GUICreate("GDI+ Example", 500, 500)
GUISetState()

; Start GDI+
_GDIPlus_Startup()
$hGraphics = _GDIPlus_GraphicsCreateFromHWND($hWnd)
_GDIPlus_GraphicsClear($hGraphics)

; Take Screenshot at bottom left of screen
$hScreenCap_hBitmap = _ScreenCapture_Capture("", 0, 0, @DesktopHeight, @DesktopWidth)
$hScreenCap_Bitmap = _GDIPlus_BitmapCreateFromHBITMAP($hScreenCap_hBitmap)


$hMatrix = _GDIPlus_MatrixCreate()
_GDIPlus_MatrixScale($hMatrix, 0.5, 0.5)
_GDIPlus_MatrixRotate($hMatrix, 90, True)


_GDIPlus_GraphicsSetTransform($hGraphics, $hMatrix)
_ScreenCapture_SaveImage (@DocumentsCommonDir & "\Transform.jpg", _GDIPlus_BitmapCreateFromGraphics(@DesktopHeight, @DesktopWidth, $hGraphics)); this line is wrong
 _GDIPlus_GraphicsDrawImageRect($hGraphics, $hScreenCap_Bitmap, 0, -400, 500, 500)

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

; Clean up resources
_WinAPI_DeleteObject($hScreenCap_hBitmap)
_GDIPlus_BitmapDispose($hScreenCap_Bitmap)
_GDIPlus_MatrixDispose($hMatrix)
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_Shutdown()

Please, help.


_____________________________________________________________________________

Share this post


Link to post
Share on other sites



Try this.

#include <GUIConstants.au3>
#include <ScreenCapture.au3>
#include <WinAPI.au3>
#Include <GDIPlus.au3>

; Create GUI
$hWnd = GUICreate("GDI+ Example", 500, 500)

; Start GDI+
_GDIPlus_Startup()
$hGraphics = _GDIPlus_GraphicsCreateFromHWND($hWnd)
$hBMPBuff = _GDIPlus_BitmapCreateFromGraphics(500, 500, $hGraphics)
$hGraphic = _GDIPlus_ImageGetGraphicsContext($hBMPBuff)

;_GDIPlus_GraphicsClear($hGraphic) ; Default Clear colour is black.

; Take Screenshot of desktop
$hScreenCap_hBitmap = _ScreenCapture_Capture("", 0, 0, @DesktopHeight, @DesktopWidth)
$hScreenCap_Bitmap = _GDIPlus_BitmapCreateFromHBITMAP($hScreenCap_hBitmap)

GUISetState() ; Placed here so that the AutoIt GUI is not captured.

$hMatrix = _GDIPlus_MatrixCreate()
_GDIPlus_MatrixScale($hMatrix, 0.5, 0.5)
_GDIPlus_MatrixRotate($hMatrix, 90, True)

_GDIPlus_GraphicsSetTransform($hGraphic, $hMatrix)
_GDIPlus_GraphicsDrawImageRect($hGraphic, $hScreenCap_Bitmap, 0, -400, 500, 500)

_GDIPlus_ImageSaveToFile($hBMPBuff, @ScriptDir & "\Transform.png")

Do
    _GDIPlus_GraphicsDrawImage($hGraphics, $hBMPBuff, 0, 0)
    Sleep(10)
Until GUIGetMsg() = $GUI_EVENT_CLOSE

ShellExecute(@ScriptDir & "\Transform.png")

; Clean up resources
_WinAPI_DeleteObject($hBMPBuff)
_WinAPI_DeleteObject($hScreenCap_hBitmap)
_GDIPlus_BitmapDispose($hScreenCap_Bitmap)
_GDIPlus_MatrixDispose($hMatrix)
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_Shutdown()

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Big thanks, Malkey, however still left one problem - background. How to trim an image, to save only transformation result?

Edit: solved. Thanks again:)

Edited by GodlessSinner

_____________________________________________________________________________

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Malkey was faster ;)

Here my version:

#include <GDIPlus.au3>
#include <GUIConstants.au3>
#include <ScreenCapture.au3>

$width = @DesktopWidth /2
$height = @DesktopHeight / 2

$hHBITMAP = _ScreenCapture_Capture("", 0, 0, $width, $height)

$hGUI = GUICreate("GDI+ Example", $width, $height)
GUISetState()

; Start GDI+
_GDIPlus_Startup()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
$hBitmap = _GDIPlus_BitmapCreateFromGraphics($width, $height, $hGraphic)
$hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsClear($hContext)
$hBmp = _GDIPlus_BitmapCreateFromHBITMAP($hHBITMAP)

$hMatrix = _GDIPlus_MatrixCreate()

_GDIPlus_MatrixRotate($hMatrix, 0)
_GDIPlus_MatrixTranslate($hMatrix, $width / 2, $height / 2)
_GDIPlus_MatrixRotate($hMatrix, 90, 0)
_GDIPlus_GraphicsSetTransform($hContext, $hMatrix)

_GDIPlus_MatrixScale($hMatrix, 0.5, 0.5)
_GDIPlus_GraphicsSetTransform($hContext, $hMatrix)

_GDIPlus_GraphicsDrawImageRect($hContext, $hBmp, -$width / 2, -$height / 2, $width, $height)


Do
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, $width, $height)
Until GUIGetMsg() = $GUI_EVENT_CLOSE

_GDIPlus_ImageSaveToFile($hBitmap, @ScriptDir & "\Test1.jpg")

_GDIPlus_MatrixDispose($hMatrix)
_GDIPlus_BitmapDispose($hBmp)
_WinAPI_DeleteObject($hHBITMAP)
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_GraphicsDispose($hContext)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_Shutdown()
GUIDelete($hGUI)
Exit

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0