Jump to content

Skew Image with GDI


BrettF
 Share

Recommended Posts

First off is it possible?

Second, I've looked through the files, I figured it was something to do with matrices but it really only had rotate from what I could see.

Any comments apreciated,

Thanks,

Brett

Link to comment
Share on other sites

I saw this but not specifically what I'm looking for.

Perhaps this image explains

Posted Image

The skew and the perspective should be quite easy. I don't know how to do the distort but I would try skew then perspctive then maybe skew at right angles.

You could create a bitmap and first of all fill it with a transparent brush.

Then use _GDIPlus_GraphicsDrawImageRectRect or _GDIPlus_GraphicsDrawImageRectRectEx to copy a section at a time, or a pixel height at a time.

So for the perspective version, say the top is $pwid and the original is $Owid, and the base is the same for both them, ie $owid.

[rough idea]

fill transparent

for $n = 0 to $picHeight-1

$indent = ($owid-$pwid)*($picHeight - $n)/($picHeight * 2)

$copy rect( 0,$n,$Owid,$n+1) to rect (Int(indent),$n,$Owid - $indent,$n+1)

next

[/rough idea]

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Malkey has made a wonderful function named _GDIplus_DrawImagePoints(), which has been included in the standard UDF package :P

Since I'm not very familiar with it I only managed to make the skewing effect, but it's a good start :(

InetGet("http://www2.vastsverige.com/ImageVault/Images/conversionFormatType_Jpeg/compressionQuality_0/width_193/filename_mymazCDldjEnXTAK0AM_.jpg/storage_Edited/scope_128/ImageVaultHandler.aspx",@DesktopDir&"\kaniner.jpg")
#include <GDIPlus.au3>


Global $width=500
Global $height=300
$hwnd=GUICreate("test",$width,$height)
GUISetState()


_GDIPlus_Startup()
$graphics=_GDIPlus_GraphicsCreateFromHWND($hwnd)
_GDIPlus_GraphicsClear($graphics,0xFF008800)
$image=_GDIPlus_ImageLoadFromFile(@DesktopDir&"\kaniner.jpg")
$iwidth=_GDIPlus_ImageGetWidth($image)
$iheight=_GDIPlus_ImageGetHeight($image)
$brush=_GDIPlus_BrushCreateSolid(0xFF000000)
$family=_GDIPlus_FontFamilyCreate("Arial")
$font=_GDIPlus_FontCreate($family,24)
$layout=_GDIPlus_RectFCreate(0,0,$width,$height)
$format=_GDIPlus_StringFormatCreate()
_GDIPlus_StringFormatSetAlign($format,1)

$centerposx=($width/2)-($iwidth/2)
$centerposy=($height/2)-($iheight/2)

_GDIplus_GraphicsDrawStringEx($graphics,"Normal",$font,$layout,$format,$brush)
_GDIPlus_GraphicsDrawImageRect($graphics,$image,$centerposx,$centerposy,$iwidth,$iheight)

Sleep(1500)

_GDIPlus_GraphicsClear($graphics,0xFF008800)
_GDIplus_GraphicsDrawStringEx($graphics,"Skew",$font,$layout,$format,$brush)
_GDIPlus_DrawImagePoints($graphics,$image,$centerposx+0,$centerposy+40,$centerposx+$iwidth,$centerposy-40,$centerposx,$centerposy+$iheight+40,3)

Sleep(1500)



Do
Until GUIGetMsg()=-3

_GDIPlus_ImageDispose($image)
_GDIPlus_BrushDispose($brush)
_GDIPlus_GraphicsDispose($graphics)
_GDIPlus_FontDispose($font)
_GDIPlus_FontFamilyDispose($family)
_GDIPlus_StringFormatDispose($format)

_GDIPlus_Shutdown()



Func _GDIPlus_StringFormatSetAlign($hStringFormat,$iFlag)
    Local $aResult
    $aResult = DllCall($ghGDIPDll, "int", "GdipSetStringFormatAlign", "ptr", $hStringFormat,"short",$iFlag)
    If @error Then Return SetError(@error, @extended, 0)
    If $aResult[0]=0 Then Return SetError(0,0,1)
    Return SetError(1,0,0)
EndFunc

:idea:

Edited by monoceres

Broken link? PM me and I'll send you the file!

Link to comment
Share on other sites

Thankyou. Having a look at it now.

Looks Great!

This is what I was trying to explain, but failed. But a script speaks a thousand pictures.

InetGet("http://www2.vastsverige.com/ImageVault/Images/conversionFormatType_Jpeg/compressionQuality_0/width_193/filename_mymazCDldjEnXTAK0AM_.jpg/storage_Edited/scope_128/ImageVaultHandler.aspx",@DesktopDir&"\kaniner.jpg")
#include <GDIPlus.au3>


Global $width=500
Global $height=300
$hwnd=GUICreate("test",$width,$height)
GUISetState()


_GDIPlus_Startup()
$graphics=_GDIPlus_GraphicsCreateFromHWND($hwnd)
_GDIPlus_GraphicsClear($graphics,0xFF008800)
$image=_GDIPlus_ImageLoadFromFile(@DesktopDir&"\kaniner.jpg")
$iwidth=_GDIPlus_ImageGetWidth($image)
$iheight=_GDIPlus_ImageGetHeight($image)
$brush=_GDIPlus_BrushCreateSolid(0xFF000000)
$family=_GDIPlus_FontFamilyCreate("Arial")
$font=_GDIPlus_FontCreate($family,24)
$layout=_GDIPlus_RectFCreate(0,0,$width,$height)
$format=_GDIPlus_StringFormatCreate()
_GDIPlus_StringFormatSetAlign($format,1)

$centerposx=($width/2)-($iwidth/2)
$centerposy=($height/2)-($iheight/2)

_GDIplus_GraphicsDrawStringEx($graphics,"Normal",$font,$layout,$format,$brush)
_GDIPlus_GraphicsDrawImageRect($graphics,$image,$centerposx,$centerposy,$iwidth,$iheight)

Sleep(1500)

_GDIPlus_GraphicsClear($graphics,0xFF008800)
_GDIplus_GraphicsDrawStringEx($graphics,"Skew",$font,$layout,$format,$brush)
$topless = 40;say top is 40 shorter than bottom
for $n = 1 to $iheight-1
    $indent = $topless*($iheight - $n)/$iheight
_GDIPlus_GraphicsDrawImageRectRect($graphics,$image,0,$n,$iwidth,1,$indent,$n,$iwidth - 2*$indent,1)
Next
$sideless = 60;say left side is 60 smalled than right side
Sleep(1500)
for $n = 1 to $iwidth-1
    $indent = $topless*($iwidth - $n)/$iwidth
_GDIPlus_GraphicsDrawImageRectRect($graphics,$image,$n,0,$n + 1,$iheight,20+$centerposx+$n,$indent,1,$iheight- 2*$indent)
Next



Do
Until GUIGetMsg()=-3

_GDIPlus_ImageDispose($image)
_GDIPlus_BrushDispose($brush)
_GDIPlus_GraphicsDispose($graphics)
_GDIPlus_FontDispose($font)
_GDIPlus_FontFamilyDispose($family)
_GDIPlus_StringFormatDispose($format)

_GDIPlus_Shutdown()



Func _GDIPlus_StringFormatSetAlign($hStringFormat,$iFlag)
    Local $aResult
    $aResult = DllCall($ghGDIPDll, "int", "GdipSetStringFormatAlign", "ptr", $hStringFormat,"short",$iFlag)
    If @error Then Return SetError(@error, @extended, 0)
    If $aResult[0]=0 Then Return SetError(0,0,1)
    Return SetError(1,0,0)
EndFunc

Haven't tried the distorting thing yet. Maybe I'll try tonight unless someone else gets there first.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Ypu could also do that with Pathes and Warp Path. If you want, you can translate the VB source from http://www.activevb.de/tipps/vb6tipps/tipp0672.html

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

Ypu could also do that with Pathes and Warp Path. If you want, you can translate the VB source from http://www.activevb.de/tipps/vb6tipps/tipp0672.html

Wow, that looks like it would take a long time! I don't think I've got that many years left to live :P

Here's the distortion anyway. Needs work to make it general but iit's just to show the idea.

InetGet("http://www2.vastsverige.com/ImageVault/Images/conversionFormatType_Jpeg/compressionQuality_0/width_193/filename_mymazCDldjEnXTAK0AM_.jpg/storage_Edited/scope_128/ImageVaultHandler.aspx",@DesktopDir&"\kaniner.jpg")
#include <GDIPlus.au3>


Global $width=500
Global $height=300
$hwnd=GUICreate("test",$width,$height)
GUISetState()


_GDIPlus_Startup()
$graphics=_GDIPlus_GraphicsCreateFromHWND($hwnd)
_GDIPlus_GraphicsClear($graphics,0xFF008800)
$image=_GDIPlus_ImageLoadFromFile(@DesktopDir&"\kaniner.jpg")
$iwidth=_GDIPlus_ImageGetWidth($image)
$iheight=_GDIPlus_ImageGetHeight($image)
$brush=_GDIPlus_BrushCreateSolid(0xFF000000)
$family=_GDIPlus_FontFamilyCreate("Arial")
$font=_GDIPlus_FontCreate($family,24)
$layout=_GDIPlus_RectFCreate(0,0,$width,$height)
$format=_GDIPlus_StringFormatCreate()
_GDIPlus_StringFormatSetAlign($format,1)

$centerposx=($width/2)-($iwidth/2)
$centerposy=($height/2)-($iheight/2)

_GDIplus_GraphicsDrawStringEx($graphics,"Normal",$font,$layout,$format,$brush)
_GDIPlus_GraphicsDrawImageRect($graphics,$image,$centerposx,$centerposy,$iwidth,$iheight)



_GDIPlus_GraphicsClear($graphics,0xFF008800)
_GDIplus_GraphicsDrawStringEx($graphics,"Distorted",$font,$layout,$format,$brush)

$hBitmap = _WinAPI_CreateCompatibleBitmapSection($iwidth,$iheight)
$hImage1 = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap)
$hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage1)
_GDIPlus_GraphicsClear($hgraphic,0xFF008800)

$topless = 40;say top is 40 shorter than bottom
for $n = 1 to $iheight-1
    $indent = $topless*($iheight - $n)/$iheight
_GDIPlus_GraphicsDrawImageRectRect($hgraphic,$image,0,$n,$iwidth,1,$indent,$n,$iwidth - 2*$indent,1)
Next


$sideless = 60;say left side is 60 smalled than right side

$Graphics2 = _GDIPlus_ImageGetGraphicsContext($hImage1)
for $n = 1 to $iwidth-1
    $indent = $topless*($iwidth - $n)/$iwidth
_GDIPlus_GraphicsDrawImageRectRect($graphics,$himage1,$n,0,$n + 1,$iheight,20+$centerposx+$n,50 + $indent,1,50 + $iheight- 2*$indent)
Next



Do
Until GUIGetMsg()=-3

_GDIPlus_ImageDispose($image)
_GDIPlus_BrushDispose($brush)
_GDIPlus_GraphicsDispose($graphics)
_GDIPlus_FontDispose($font)
_GDIPlus_FontFamilyDispose($family)
_GDIPlus_StringFormatDispose($format)

_GDIPlus_Shutdown()



Func _GDIPlus_StringFormatSetAlign($hStringFormat,$iFlag)
    Local $aResult
    $aResult = DllCall($ghGDIPDll, "int", "GdipSetStringFormatAlign", "ptr", $hStringFormat,"short",$iFlag)
    If @error Then Return SetError(@error, @extended, 0)
    If $aResult[0]=0 Then Return SetError(0,0,1)
    Return SetError(1,0,0)
EndFunc

Func _WinAPI_CreateCompatibleBitmapSection($iWidth,$iHeight,$iBitCount=24)
    
    $tBMI = DllStructCreate($tagBITMAPINFO)
    DllStructSetData($tBMI, "Size", DllStructGetSize($tBMI) - 4)
    DllStructSetData($tBMI, "Width", $iWidth)
    DllStructSetData($tBMI, "Height", $iHeight)
    DllStructSetData($tBMI, "Planes", 1)
    DllStructSetData($tBMI, "BitCount", $iBitCount)

    $aDIB = DllCall('gdi32.dll', 'ptr', 'CreateDIBSection', _
            'ptr', 0, _
            'ptr', DllStructGetPtr($tBMI), _
            'uint', 1, _
            'ptr*', 0, _
            'ptr', 0, _
            'uint', 0)  
    Return $aDib[0]
    
EndFunc
Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Ah I love you guys!

I couldn't resist playing with it

InetGet("http://www2.vastsverige.com/ImageVault/Images/conversionFormatType_Jpeg/compressionQuality_0/width_193/filename_mymazCDldjEnXTAK0AM_.jpg/storage_Edited/scope_128/ImageVaultHandler.aspx",@DesktopDir&"\kaniner.jpg")
#include <GDIPlus.au3>


Global $width=500
Global $height=300
$hwnd=GUICreate("test",$width,$height)
GUISetBkColor(0x008800)
$btn = GUICtrlCreateButton("again",10,10,80,20)
GUISetState()


_GDIPlus_Startup()
$graphics=_GDIPlus_GraphicsCreateFromHWND($hwnd)
_GDIPlus_GraphicsClear($graphics,0xFF008800)
$image=_GDIPlus_ImageLoadFromFile(@DesktopDir&"\kaniner.jpg")
$iwidth=_GDIPlus_ImageGetWidth($image)
$iheight=_GDIPlus_ImageGetHeight($image)
$brush=_GDIPlus_BrushCreateSolid(0xFF000000)
$family=_GDIPlus_FontFamilyCreate("Arial")
$font=_GDIPlus_FontCreate($family,24)
$layout=_GDIPlus_RectFCreate(0,0,$width,$height)
$format=_GDIPlus_StringFormatCreate()
_GDIPlus_StringFormatSetAlign($format,1)

$centerposx=($width/2)-($iwidth/2)
$centerposy=($height/2)-($iheight/2)

_GDIplus_GraphicsDrawStringEx($graphics,"Normal",$font,$layout,$format,$brush)
_GDIPlus_GraphicsDrawImageRect($graphics,$image,$centerposx,$centerposy,$iwidth,$iheight)



_GDIPlus_GraphicsClear($graphics,0xFF008800)
_GDIplus_GraphicsDrawStringEx($graphics,"Distorted",$font,$layout,$format,$brush)

$hBitmap = _WinAPI_CreateCompatibleBitmapSection($iwidth,$iheight)
$hImage1 = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap)
$hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage1)
doitagain()
Do
    $msg = GUIGetMsg()
    if $msg =-3 then exitloop
    if $msg = $btn then doitagain()
Until 0

_GDIPlus_ImageDispose($image)
_GDIPlus_BrushDispose($brush)
_GDIPlus_GraphicsDispose($graphics)
_GDIPlus_FontDispose($font)
_GDIPlus_FontFamilyDispose($family)
_GDIPlus_StringFormatDispose($format)

_GDIPlus_Shutdown()



Func _GDIPlus_StringFormatSetAlign($hStringFormat,$iFlag)
    Local $aResult
    $aResult = DllCall($ghGDIPDll, "int", "GdipSetStringFormatAlign", "ptr", $hStringFormat,"short",$iFlag)
    If @error Then Return SetError(@error, @extended, 0)
    If $aResult[0]=0 Then Return SetError(0,0,1)
    Return SetError(1,0,0)
EndFunc

Func doitagain()
;ControlFocus($hwnd,"",$btn)
    
    $a = 1 
$b = 60
$step = 1
while 1
for $r = $a to $b step $step
_GDIPlus_GraphicsClear($hgraphic,0xFF008800)
DllCall("user32.dll", "int", "InvalidateRect", "hwnd", GUICtrlGetHandle($Btn), "int", 0, "int", 1)

$topless = $r;say top is 40 shorter than bottom
for $n = 1 to $iheight-3
    $indent = $topless*($iheight - $n)/$iheight
_GDIPlus_GraphicsDrawImageRectRect($hgraphic,$image,1,$n,$iwidth,1,$indent,$n,$iwidth - 2*$indent,1)
Next


$sideless = $r;say left side is 60 smalled than right side

$Graphics2 = _GDIPlus_ImageGetGraphicsContext($hImage1)
for $n = 0 to $iwidth-1
    $indent = $topless*($iwidth - $n)/$iwidth
_GDIPlus_GraphicsDrawImageRectRect($graphics,$himage1,$n,0,$n + 1,$iheight+1,20+$centerposx+$n,50 + $indent,1,50 + $iheight- 2*$indent+1)
Next


next;$r
if $b = 1 then exitloop
$a = 60
$b = 1
$step = -1
WEnd
EndFunc
Func _WinAPI_CreateCompatibleBitmapSection($iWidth,$iHeight,$iBitCount=24)
    
    $tBMI = DllStructCreate($tagBITMAPINFO)
    DllStructSetData($tBMI, "Size", DllStructGetSize($tBMI) - 4)
    DllStructSetData($tBMI, "Width", $iWidth)
    DllStructSetData($tBMI, "Height", $iHeight)
    DllStructSetData($tBMI, "Planes", 1)
    DllStructSetData($tBMI, "BitCount", $iBitCount)

    $aDIB = DllCall('gdi32.dll', 'ptr', 'CreateDIBSection', _
            'ptr', 0, _
            'ptr', DllStructGetPtr($tBMI), _
            'uint', 1, _
            'ptr*', 0, _
            'ptr', 0, _
            'uint', 0)  
    Return $aDib[0]
    
EndFunc
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...