Jump to content

Help with strings


Werty
 Share

Recommended Posts

So I have a line that looks like this...

$msgs = $img.Convert($5,$8,$7,$1,$2&$c1,$1,$2&$c2,$1,$2&$c3,$1,$2&$c4,$1,$2&$c5,$1,$2&$c6,$1,$2&$c7,$1,$2&$c8,$1,$2&$c9,$6)

..how do I put all that into a single string ?

This doesnt work

$string = "$5,$8,$7,$1,$2&$c1,$1,$2&$c2,$1,$2&$c3,$1,$2&$c4,$1,$2&$c5,$1,$2&$c6,$1,$2&$c7,$1,$2&$c8,$1,$2&$c9,$6"
$msgs = $img.Convert($string)

All the variables are strings, like..

Global $1 = "-draw", $2 = "line", etc, etc, etc

Notice the &'s in the string.

Edited by Werty

Some guy's script + some other guy's script = my script!

Link to comment
Share on other sites

Opt("ExpandVarStrings", 1)      ;0=don't expand, 1=do expand
$msgs = $img.Convert("$5,$8,$7,$1,$2&$c1,$1,$2&$c2,$1,$2&$c3,$1,$2&$c4,$1,$2&$c5,$1,$2&$c6,$1,$2&$c7,$1,$2&$c8,$1,$2&$c9,$6")

I cant get that working, I tried...

Opt("ExpandVarStrings", 1)      ;0=don't expand, 1=do expand
$string = "$5,$8,$7,$1,$2&$c1,$1,$2&$c2,$1,$2&$c3,$1,$2&$c4,$1,$2&$c5,$1,$2&$c6,$1,$2&$c7,$1,$2&$c8,$1,$2&$c9,$6"
$msgs = $img.Convert($string)

The line works as I wrote it in the OP, I just need it something like the above, like $img.Convert($string)

Edited by Werty

Some guy's script + some other guy's script = my script!

Link to comment
Share on other sites

Here's a fully working example (requires ImageMagickObject.dll)...

#include <GDIPlus.au3>
#include <ClipBoard.au3>
$img = ObjCreate("ImageMagickObject.MagickImage.1")
Global $1="-draw",$2="line ",$5="-size",$6="clipboard:",$7="xc:white",$8="640x480"
Global $c1="100,100 100,200",$c2="100,200 200,200"
$gui = GUICreate("example", 640, 480)
GUISetState()
_GDIPlus_Startup()
$img.Convert($5,$8,$7,$1,$2&$c1,$1,$2&$c2,$6)
$pic1 = makegraphic()
$hgraphic = _GDIPlus_GraphicsCreateFromHWND($gui)
_GDIPlus_GraphicsDrawImage($hgraphic, $pic1, 0, 0)
Sleep(3000)
_GDIPLUS_Shutdown()
Func makegraphic()
_ClipBoard_Open(WinGetHandle(AutoItWinGetTitle()))
$image = _ClipBoard_GetDataEx($CF_BITMAP)
_ClipBoard_Close()
$hbitmap = _GDIPlus_BitmapCreateFromHBITMAP($image)
$hgraphic = _GDIPlus_GraphicsCreateFromHWND($gui)
Return $hbitmap
EndFunc

...which I need to be something like this (which doesnt work)...

#include <GDIPlus.au3>
#include <ClipBoard.au3>
$img = ObjCreate("ImageMagickObject.MagickImage.1")
Global $1="-draw",$2="line ",$5="-size",$6="clipboard:",$7="xc:white",$8="640x480"
Global $c1="100,100 100,200",$c2="100,200 200,200"
$gui = GUICreate("Example", 640, 480)
GUISetState()
_GDIPlus_Startup()
$string = "$5,$8,$7,$1,$2&$c1,$1,$2&$c2,$6"
$img.Convert($string)
$pic1 = makegraphic()
$hgraphic = _GDIPlus_GraphicsCreateFromHWND($gui)
_GDIPlus_GraphicsDrawImage($hgraphic, $pic1, 0, 0)
Sleep(3000)
_GDIPLUS_Shutdown()
Func makegraphic()
_ClipBoard_Open(WinGetHandle(AutoItWinGetTitle()))
$image = _ClipBoard_GetDataEx($CF_BITMAP)
_ClipBoard_Close()
$hbitmap = _GDIPlus_BitmapCreateFromHBITMAP($image)
$hgraphic = _GDIPlus_GraphicsCreateFromHWND($gui)
Return $hbitmap
EndFunc

So I would like this line...

$img.Convert($5,$8,$7,$1,$2&$c1,$1,$2&$c2,$6)

...to be something like...

$string = "$5,$8,$7,$1,$2&$c1,$1,$2&$c2,$6"
$img.Convert($string)

?

Edited by Werty

Some guy's script + some other guy's script = my script!

Link to comment
Share on other sites

Try this.

#include <GDIPlus.au3>
#include <ClipBoard.au3>

Global $img = ObjCreate("ImageMagickObject.MagickImage.1")
Global $1 = "-draw", $2 = "line ", $5 = "-size", $6 = "clipboard:", $7 = "xc:white", $8 = "640x480"
Global $c1 = "100,100 100,200", $c2 = "100,200 200,200"
Global $str = "$img.Convert("

Global $gui = GUICreate("example", 640, 480)
GUISetState()
_GDIPlus_Startup()

Global $string = "$5,$8,$7,$1,$2&$c1,$1,$2&$c2,$6"

#cs
Local $arr = StringSplit($string, ",", 2)
For $i = 0 To UBound($arr) - 1
    $str &= '"' & Execute($arr[$i]) & '",'
Next
$str = StringTrimRight($str, 1) & ")"
#ce

; or

;$str = "$img.Convert(" & StringReplace(Execute('"' & StringRegExpReplace($string, '([^,]+)', '#" & \1 & "#') & '"'), "#", '"') & ")"

;or simply

;$str = "$img.Convert($5,$8,$7,$1,$2&$c1,$1,$2&$c2,$6)"
$str = "$img.Convert(" & $string & ")"
;ConsoleWrite($str & @LF)

Execute($str)
;Execute('$img.Convert("-size","640x480","xc:white","-draw","line 100,100 100,200","-draw","line 100,200 200,200","clipboard:")')

$pic1 = makegraphic()
$hgraphic = _GDIPlus_GraphicsCreateFromHWND($gui)
_GDIPlus_GraphicsDrawImage($hgraphic, $pic1, 0, 0)
Sleep(3000)
_GDIPlus_Shutdown()


Func makegraphic()
    _ClipBoard_Open(WinGetHandle(AutoItWinGetTitle()))
    $image = _ClipBoard_GetDataEx($CF_BITMAP)
    _ClipBoard_Close()
    $hbitmap = _GDIPlus_BitmapCreateFromHBITMAP($image)
    $hgraphic = _GDIPlus_GraphicsCreateFromHWND($gui)
    Return $hbitmap
EndFunc   ;==>makegraphic

Edit: Added ;or simply method

Edited by Malkey
Link to comment
Share on other sites

Edit: Added ;or simply method

Read about Execute() a while ago and was like "hmmm, this could come in handy", guess I was right :)

I went with the ;or simply method, thanks :mellow:

Some guy's script + some other guy's script = my 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...