Sign in to follow this  
Followers 0
Deathbringer

..

5 posts in this topic

#1 ·  Posted (edited)

Posted Image Edited by JosIsaFucktard

Share this post


Link to post
Share on other sites



Try this:

#AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GDIPlus.au3>

If Not _GDIPlus_Startup() Then Exit MsgBox(16, "GDI+ initialization failed", "The program cannot continue.", 10)
Global $sPath = @ScriptDir & "\Tic-Tac-Toe.png"

Global $hImageOld = _GDIPlus_ImageLoadFromFile($sPath)
_ResizeImage(False, @ScriptDir & "\Resized.jpg", $hImageOld)
_ResizeImage(True, @ScriptDir & "\Rotated.jpg", $hImageOld)
_GDIPlus_ImageDispose($hImageOld)
_GDIPlus_Shutdown()
Exit

Func _ResizeImage($f_Rotate, $s_OutPath, $hImage, $f_Degree = 90, $iNewWidth = 619, $iNewHeight = 1400)
    Local $iStride = 0, $iPixelFormat = 0x0026200A, $pScan0 = 0
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iNewWidth, "int", $iNewHeight, "int", $iStride, "int", $iPixelFormat, "ptr", $pScan0, "int*", 0)
    Local $hBitmap = $aResult[6]
    Local  $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    Local $hMatrix = _GDIPlus_MatrixCreate()
    If $f_Rotate Then
        _GDIPlus_MatrixTranslate($hMatrix, $iNewWidth / 2, $iNewHeight / 2)
        _GDIPlus_MatrixRotate($hMatrix, $f_Degree, "False")
        _GDIPlus_GraphicsSetTransform($hBackbuffer, $hMatrix)
        _GDIPlus_GraphicsDrawImageRect($hBackbuffer, $hImage,  -$iNewWidth / 2, -$iNewHeight / 2, $iNewWidth, $iNewHeight)
    Else
        _GDIPlus_GraphicsDrawImageRect($hBackbuffer, $hImage,  0, 0, $iNewWidth, $iNewHeight)
    EndIf
    _GDIPlus_ImageSaveToFile($hBitmap, $s_OutPath)
    _GDIPlus_MatrixDispose($hMatrix)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_GraphicsDispose($hBackbuffer)
EndFunc   ;==>_ResizeImage

Br,

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

#include <GDIPlus.au3>

_GDIPlus_Startup()
Local $hImg = _GDIPlus_ImageLoadFromFile("tic_tac_toe.png")

_GDIPlus_ImageRotateFlip($hImg, 1)
_GDIPlus_ImageSaveToFile($hImg, "Test.png")
_GDIPlus_ImageDispose($hImg)

_GDIPlus_Shutdown()

; #FUNCTION# ====================================================================================================================
; Name...........: _GDIPlus_ImageRotateFlip
; Description ...: Rotates and flips an image
; Syntax.........: _GDIPlus_ImageRotateFlip($hImage, $iRotateFlipType)
; Parameters ....: $hImage          - Pointer to an Image object
;                  $iRotateFlipType - Type of rotation and flip:
;                  |0 - No rotation and no flipping (A 180-degree rotation, a horizontal flip and then a vertical flip)
;                  |1 - A 90-degree rotation without flipping (A 270-degree rotation, a horizontal flip and then a vertical flip)
;                  |2 - A 180-degree rotation without flipping (No rotation, a horizontal flip folow by a vertical flip)
;                  |3 - A 270-degree rotation without flipping (A 90-degree rotation, a horizontal flip and then a vertical flip)
;                  |4 - No rotation and a horizontal flip (A 180-degree rotation followed by a vertical flip)
;                  |5 - A 90-degree rotation followed by a horizontal flip (A 270-degree rotation followed by a vertical flip)
;                  |6 - A 180-degree rotation followed by a horizontal flip (No rotation and a vertical flip)
;                  |7 - A 270-degree rotation followed by a horizontal flip (A 90-degree rotation followed by a vertical flip)
; Return values .: Success      - True
;                  Failure      - False
; Remarks .......: None
; Related .......: None
; Link ..........; @@MsdnLink@@ GdipImageRotateFlip
; Example .......; No
; ===============================================================================================================================
Func _GDIPlus_ImageRotateFlip($hImage, $iRotateFlipType)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipImageRotateFlip", "hwnd", $hImage, "int", $iRotateFlipType)

    Return SetError($aResult[0], 0, $aResult[0] = 0)
EndFunc   ;==>_GDIPlus_ImageRotateFlip

Share this post


Link to post
Share on other sites

Hi, thanks Authenticity, nice.

Another gdip function for my personal collection... sweet.

For the op resize and rotate using Authenticity function.

#AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GDIPlus.au3>

_ResizeRotate(@ScriptDir & "\tic_tac_toe.png", @ScriptDir & "\Rotate90.jpg", 700, 300, 1)


Func _ResizeRotate($sInFile, $sOutFile, $iWidth, $iHeight, $iRotate)
    Local $hInImage, $hInGraphic, $hOutImage, $hOutGraphic
    _GDIPlus_Startup()

    $hInImage = _GDIPlus_ImageLoadFromFile($sInFile)
    _GDIPlus_ImageRotateFlip($hInImage, $iRotate)

    $hInGraphic = _GDIPlus_ImageGetGraphicsContext($hInImage)
    $hOutImage = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hInGraphic)
    _GDIPlus_GraphicsDispose($hInGraphic)

    $hOutGraphic = _GDIPlus_ImageGetGraphicsContext($hOutImage)
    _GDIPlus_GraphicsDrawImageRect($hOutGraphic, $hInImage, 0, 0, $iWidth, $iHeight)
    _GDIPlus_GraphicsDispose($hOutGraphic)
    _GDIPlus_ImageDispose($hInImage)

    _GDIPlus_ImageSaveToFile($hOutImage, $sOutFile)
    _GDIPlus_ImageDispose($hOutImage)

    _GDIPlus_Shutdown()
EndFunc   ;==>_ResizeRotate


; #FUNCTION# ====================================================================================================================
; Name...........: _GDIPlus_ImageRotateFlip
; Description ...: Rotates and flips an image
; Syntax.........: _GDIPlus_ImageRotateFlip($hImage, $iRotateFlipType)
; Parameters ....: $hImage          - Pointer to an Image object
;                  $iRotateFlipType - Type of rotation and flip:
;                  |0 - No rotation and no flipping (A 180-degree rotation, a horizontal flip and then a vertical flip)
;                  |1 - A 90-degree rotation without flipping (A 270-degree rotation, a horizontal flip and then a vertical flip)
;                  |2 - A 180-degree rotation without flipping (No rotation, a horizontal flip folow by a vertical flip)
;                  |3 - A 270-degree rotation without flipping (A 90-degree rotation, a horizontal flip and then a vertical flip)
;                  |4 - No rotation and a horizontal flip (A 180-degree rotation followed by a vertical flip)
;                  |5 - A 90-degree rotation followed by a horizontal flip (A 270-degree rotation followed by a vertical flip)
;                  |6 - A 180-degree rotation followed by a horizontal flip (No rotation and a vertical flip)
;                  |7 - A 270-degree rotation followed by a horizontal flip (A 90-degree rotation followed by a vertical flip)
; Return values .: Success      - True
;                  Failure      - False
; Remarks .......: None
; Related .......: None
; Link ..........; @@MsdnLink@@ GdipImageRotateFlip
; Example .......; No
; ===============================================================================================================================
Func _GDIPlus_ImageRotateFlip($hImage, $iRotateFlipType)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipImageRotateFlip", "hwnd", $hImage, "int", $iRotateFlipType)

    Return SetError($aResult[0], 0, $aResult[0] = 0)
EndFunc   ;==>_GDIPlus_ImageRotateFlip

Cheers

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Yes, to have a closer look to GDIp.au3 would save a lot of time for finding a solution to rotate and save and image by 90° steps... :x

Here another method for a rotation of -90,90,-270,270:

;~ #AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GDIPlus.au3>

If Not _GDIPlus_Startup() Then Exit MsgBox(16, "GDI+ initialization failed", "The program cannot continue.", 10)
Global $sPath = @ScriptDir & "\tictactoey.jpg"

Global $hImageOld = _GDIPlus_ImageLoadFromFile($sPath)
_ResizeImage(False, @ScriptDir & "\Resized.jpg", $hImageOld)
_ResizeImage(True, @ScriptDir & "\Rotated.jpg", $hImageOld)
_GDIPlus_ImageDispose($hImageOld)
_GDIPlus_Shutdown()
Exit

Func _ResizeImage($f_Rotate, $s_OutPath, $hImage, $f_Degree = 90, $iNewWidth = 618, $iNewHeight = 1376)
    Local $iStride = 0, $iPixelFormat = 0x0026200A, $pScan0 = 0
    Local $iW = _GDIPlus_ImageGetWidth($hImage)
    Local $iH = _GDIPlus_ImageGetHeight($hImage)
    Local $bD = $iW + $iH
    If $f_Rotate Then
        Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $bD, "int", $bD, "int", $iStride, "int", $iPixelFormat, "ptr", $pScan0, "int*", 0)
    Else
        Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int",  $iNewWidth, "int", $iNewHeight, "int", $iStride, "int", $iPixelFormat, "ptr", $pScan0, "int*", 0)
    EndIf
    Local $hBitmap = $aResult[6]
    Local  $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    DllCall($ghGDIPDll, "uint", "GdipSetInterpolationMode", "hwnd", $hBackbuffer, "int", 5)

    If $f_Rotate And (Abs($f_Degree) = 90 Or Abs($f_Degree) = 270) Then
        $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iH, "int", $iW, "int", $iStride, "int", $iPixelFormat, "ptr", $pScan0, "int*", 0)
        Local $hBitmap2 = $aResult[6]
        Local  $hBackbuffer2 = _GDIPlus_ImageGetGraphicsContext($hBitmap2)
        DllCall($ghGDIPDll, "uint", "GdipSetInterpolationMode", "hwnd", $hBackbuffer2, "int", 5)
        Local $hMatrix = _GDIPlus_MatrixCreate()
        _GDIPlus_MatrixTranslate($hMatrix, $bD / 2, $bD / 2)
        _GDIPlus_MatrixRotate($hMatrix, $f_Degree, 0)
        _GDIPlus_MatrixTranslate($hMatrix, -$bD / 2, -$bD / 2)
        _GDIPlus_GraphicsSetTransform($hBackbuffer, $hMatrix)
        _GDIPlus_GraphicsDrawImageRect($hBackbuffer, $hImage, $bD / 2 - $iW / 2, $bD / 2 - $iH / 2, $iW, $iH)
         $aResult = DllCall($ghGDIPDll, "uint", "GdipCloneImage", "hwnd", $hBitmap, "int*", 0)
         $hTemp =  $aResult[2]
        DllCall($ghGDIPDll, "uint", "GdipSetInterpolationMode", "hwnd", $hTemp, "int", 5)
        _GDIPlus_GraphicsDrawImageRectRect($hBackbuffer2, $hTemp,  $bD / 2 - $iH / 2, $bD / 2 - $iW / 2, $iH, $iW, 0, 0, $iH, $iW)
        _GDIPlus_ImageSaveToFile($hBitmap2, $s_OutPath)
        _GDIPlus_BitmapDispose($hTemp)
        _GDIPlus_MatrixDispose($hMatrix)
        _GDIPlus_BitmapDispose($hBitmap2)
        _GDIPlus_GraphicsDispose($hBackbuffer2)
    Else
        _GDIPlus_GraphicsDrawImageRect($hBackbuffer, $hImage,  0, 0, $iNewWidth, $iNewHeight)
        _GDIPlus_ImageSaveToFile($hBitmap, $s_OutPath)
    EndIf
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_GraphicsDispose($hBackbuffer)
EndFunc   ;==>_ResizeImage

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