Jump to content
Sign in to follow this  
Andreik

GDI+

Recommended Posts

Andreik

I write a simple GDI+ example, maybe some people will learn something new.

#include <GDIPlus.au3>
#include <Misc.au3>

Func GdipRotateTextureTransform($hBrush,$Angle,$MatrixOrder=0)
    Local $DLL = "gdiplus.dll"
    Local $RESULT
    $RESULT = DllCall($DLL,"int","GdipRotateTextureTransform","int",$hBrush,"float",$Angle,"int",$MatrixOrder)
EndFunc

Func GdipCreateTexture($hImg,$WrapMode=0x00)
    Local $DLL = "gdiplus.dll"
    Local $RESULT
    $RESULT = DllCall($DLL,"int","GdipCreateTexture","int",$hImg,"int",$WrapMode,"int*",0)
    Return $RESULT[3]
EndFunc

Func GdipScaleTextureTransform($hBrush,$SX,$SY,$MatrixOrder=0x00)
    Local $DLL = "gdiplus.dll"
    Local $RESULT
    $RESULT = DllCall($DLL,"int","GdipScaleTextureTransform","int",$hBrush,"float",$SX,"float",$SY,"int",$MatrixOrder)
EndFunc


_GDIPlus_Startup()
$ANGLE = 0
$LOAD = FileOpenDialog("IMAGE",@DesktopDir,"Images (*.jpg;*.png;*.bmp;*.gif;*.tif)",1)
If @error Then Exit
$ZOOM = InputBox("ZOOM","Please select zoom","1")
$IMAGE = _GDIPlus_ImageLoadFromFile($LOAD)
$X = _GDIPlus_ImageGetWidth($IMAGE)*$ZOOM
$Y = _GDIPlus_ImageGetHeight($IMAGE)*$ZOOM
$GUI = GUICreate("GDI+",$X,$Y,-1,-1,0x80000000)
$GRAPHIC = _GDIPlus_GraphicsCreateFromHWND($GUI)
GUISetState(@SW_SHOW,$GUI)
$BRUSH = GdipCreateTexture($IMAGE,0x00)
GdipScaleTextureTransform($BRUSH,$ZOOM,$ZOOM,0x00)
_GDIPlus_GraphicsFillRect($GRAPHIC,0,0,$X,$Y,$BRUSH)
While 1
    $MSG = GUIGetMsg()
    If _IsPressed('25') Then
        GdipRotateTextureTransform($BRUSH,$ANGLE+1,0)
        _GDIPlus_GraphicsFillRect($GRAPHIC,0,0,$X,$Y,$BRUSH)
    ElseIf _IsPressed('27') Then
        GdipRotateTextureTransform($BRUSH,$ANGLE-1,0)
        _GDIPlus_GraphicsFillRect($GRAPHIC,0,0,$X,$Y,$BRUSH)
    ElseIf $MSG = -3 Then
        _GDIPlus_BrushDispose($BRUSH)
        _GDIPlus_ImageDispose($IMAGE)
        _GDIPlus_GraphicsDispose($GRAPHIC)
        _GDIPlus_Shutdown()
        Exit
    EndIf
    Sleep(15)
WEnd

When the words fail... music speaks

Share this post


Link to post
Share on other sites
Zinthose

Very Nice, I love the effect is creates with the previously painted image.

FYI: You forgot to mention, You have to Press <Left Arrow> or <Right Arrow> to activate rotation and Press <Esc> to exit.


--- TTFN

Share this post


Link to post
Share on other sites
Andreik

Very Nice, I love the effect is creates with the previously painted image.

FYI: You forgot to mention, You have to Press <Left Arrow> or <Right Arrow> to activate rotation and Press <Esc> to exit.

Yeah. Thanks for you mentions. ;) I'm forgetful.


When the words fail... music speaks

Share this post


Link to post
Share on other sites
WeMartiansAreFriendly

Very nice! I sense an image viewer coming soon. ;)

#include <GDIPlus.au3>
#include <Misc.au3>

Func GdipRotateTextureTransform($hBrush,$Angle,$MatrixOrder=0)
    Local $DLL = "gdiplus.dll"
    Local $RESULT
    $RESULT = DllCall($DLL,"int","GdipRotateTextureTransform","int",$hBrush,"float",$Angle,"int",$MatrixOrder)
EndFunc

Func GdipCreateTexture($hImg,$WrapMode=0x00)
    Local $DLL = "gdiplus.dll"
    Local $RESULT
    $RESULT = DllCall($DLL,"int","GdipCreateTexture","int",$hImg,"int",$WrapMode,"int*",0)
    Return $RESULT[3]
EndFunc

Func GdipScaleTextureTransform($hBrush,$SX,$SY,$MatrixOrder=0x00)
    Local $DLL = "gdiplus.dll"
    Local $RESULT
    $RESULT = DllCall($DLL,"int","GdipScaleTextureTransform","int",$hBrush,"float",$SX,"float",$SY,"int",$MatrixOrder)
EndFunc


_GDIPlus_Startup()
$ANGLE = 0
$LOAD = FileOpenDialog("IMAGE",@DesktopDir,"Images (*.jpg;*.png;*.bmp;*.gif;*.tif)",1)
If @error Then Exit
$ZOOM = InputBox("ZOOM","Please select zoom","1")
$IMAGE = _GDIPlus_ImageLoadFromFile($LOAD)
$X = _GDIPlus_ImageGetWidth($IMAGE)*$ZOOM
$Y = _GDIPlus_ImageGetHeight($IMAGE)*$ZOOM
$GUI = GUICreate("GDI+",$X,$Y,-1,-1,0x80000000)
$GRAPHIC = _GDIPlus_GraphicsCreateFromHWND($GUI)
GUISetState(@SW_SHOW,$GUI)


$BRUSH = GdipCreateTexture($IMAGE,0x00)
GdipScaleTextureTransform($BRUSH,$ZOOM,$ZOOM,0x00)
_GDIPlus_GraphicsFillRect($GRAPHIC,0,0,$X,$Y,$BRUSH)


While 1
    $MSG = GUIGetMsg()
    If _IsPressed('25') Then ;left
        GdipRotateTextureTransform($BRUSH,$ANGLE +1, 0)
        _GDIPlus_GraphicsFillRect($GRAPHIC,0,0,$X,$Y,$BRUSH)
        
    ElseIf _IsPressed('26') Then ;up
        GdipScaleTextureTransform($BRUSH,$ZOOM +0.1,$ZOOM +0.1,0x00)
        _GDIPlus_GraphicsFillRect($GRAPHIC,0,0,$X,$Y,$BRUSH)
        
    ElseIf _IsPressed('27') Then ;right
        GdipRotateTextureTransform($BRUSH,$ANGLE -0.1, 0)
        _GDIPlus_GraphicsFillRect($GRAPHIC,0,0,$X,$Y,$BRUSH)
        
    ElseIf  _IsPressed('28') Then ;down
        GdipScaleTextureTransform($BRUSH,$ZOOM -0.1,$ZOOM -0.1,0x00)
        _GDIPlus_GraphicsFillRect($GRAPHIC,0,0,$X,$Y,$BRUSH)
        
    ElseIf $MSG = -3 Then
        _GDIPlus_BrushDispose($BRUSH)
        _GDIPlus_ImageDispose($IMAGE)
        _GDIPlus_GraphicsDispose($GRAPHIC)
        _GDIPlus_Shutdown()
        Exit
    EndIf
    Sleep(15)
WEnd

Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet()

Share this post


Link to post
Share on other sites
ptrex
Alek

sweet, needed this ;)

Edited by Alek

[font="Impact"]Never fear, I is here.[/font]

Share this post


Link to post
Share on other sites
Andreik

Thanks guys. ;)


When the words fail... music speaks

Share this post


Link to post
Share on other sites
rasim

Andreik

Very nice my friend! ;)

Share this post


Link to post
Share on other sites
UEZ

Thanks for sharing knowledge! I learned something new... ;)

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
UEZ

I made some simple modifications:

#include <GDIPlus.au3>
#include <Misc.au3>

_GDIPlus_Startup()
$ANGLE = 0
$LOAD = FileOpenDialog("IMAGE", @DesktopDir, "Images (*.jpg;*.png;*.bmp;*.gif;*.tif)", 1)
If @error Then Exit
$ZOOM = 1
$IMAGE = _GDIPlus_ImageLoadFromFile($LOAD)
$X = _GDIPlus_ImageGetWidth($IMAGE) * $ZOOM
$Y = _GDIPlus_ImageGetHeight($IMAGE) * $ZOOM
$GUI = GUICreate("GDI+", $X, $Y, -1, -1, 0x80000000)
$GRAPHIC = _GDIPlus_GraphicsCreateFromHWND($GUI)
GUISetState(@SW_SHOW, $GUI)
$BRUSH = GdipCreateTexture($IMAGE, 0x00)
GdipScaleTextureTransform($BRUSH, $ZOOM, $ZOOM, 0x00)
_GDIPlus_GraphicsFillRect($GRAPHIC, 0, 0, $X, $Y, $BRUSH)

$i = 0
$degree = 360
$pi = 3.1415926535897932
$zoom_factor = 0.002
While 1
    $MSG = GUIGetMsg()

    If $i <= 2 * $degree Then
        GdipRotateTextureTransform($BRUSH, $ANGLE + 1 * Cos($i * $pi / 180) * Random(2, 4, 0) * ATan($i * $pi / 180), 0)
        GdipScaleTextureTransform($BRUSH, $ZOOM - $zoom_factor, $ZOOM - $zoom_factor, 0x00)
    Else
        GdipRotateTextureTransform($BRUSH, $ANGLE - 1 * Sin($i * $pi / 180) * Random(2, 4, 0) * ATan($i * $pi / 180), 0)
        GdipScaleTextureTransform($BRUSH, $ZOOM + $zoom_factor, $ZOOM + $zoom_factor, 0x00)
    EndIf
    _GDIPlus_GraphicsFillRect($GRAPHIC, 0, 0, $X, $Y, $BRUSH)
    $i += 1
    If $i = 4 * $degree - 1 Then $i = 0
    Sleep(1)
    If $MSG = -3 Then
        _GDIPlus_BrushDispose($BRUSH)
        _GDIPlus_ImageDispose($IMAGE)
        _GDIPlus_GraphicsDispose($GRAPHIC)
        _GDIPlus_Shutdown()
        Exit
    EndIf
    Sleep(15)
WEnd

Func GdipRotateTextureTransform($hBrush, $ANGLE, $MatrixOrder = 0x00)
    Local $DLL = "gdiplus.dll"
    Local $RESULT
    $RESULT = DllCall($DLL, "int", "GdipRotateTextureTransform", "int", $hBrush, "float", $ANGLE, "int", $MatrixOrder)
EndFunc   ;==>GdipRotateTextureTransform

Func GdipCreateTexture($hImg, $WrapMode = 0x00)
    Local $DLL = "gdiplus.dll"
    Local $RESULT
    $RESULT = DllCall($DLL, "int", "GdipCreateTexture", "int", $hImg, "int", $WrapMode, "int*", 0)
    Return $RESULT[3]
EndFunc   ;==>GdipCreateTexture

Func GdipScaleTextureTransform($hBrush, $SX, $SY, $MatrixOrder = 0x00)
    Local $DLL = "gdiplus.dll"
    Local $RESULT
    $RESULT = DllCall($DLL, "int", "GdipScaleTextureTransform", "int", $hBrush, "float", $SX, "float", $SY, "int", $MatrixOrder)
EndFunc   ;==>GdipScaleTextureTransform

Maybe you like it!

UEZ

Edit: dynamic zooming

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
Andreik

I like your modifications. ;) Is very hypnotist. ;):D


When the words fail... music speaks

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  

×