Sign in to follow this  
Followers 0
Mehoron

String Split Integer Manipulation

12 posts in this topic

Hey Guys,

So I'm trying to split a string into int's so I can run some math on the results.

I've tried converting the strings using Int($string), but this simply returns zero, calling just $string will still give me the proper number. Could I be doing something wrong or is there a bug here.

$tile_dimension = StringSplit(_GetFileProperty("C:\Image.jpg", "Dimensions"), " x ", 1)
$tile_width = $tile_dimension[1]
$tile_height = $tile_dimension[2]
$number_of_tiles = $tile_width/64

Again I have already tried by doing $number_of_tiles = Int($tile_width), and $number_of_tiles returns 0.

Share this post


Link to post
Share on other sites



Where did you find _GetFileProperty function ?


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

Where did you find _GetFileProperty function ?

Share this post


Link to post
Share on other sites

When i try

#include <GetFileProperty.au3>

$tile_dimension = StringSplit(_GetFileProperty("D:\Wallpapers\041_abstract-wallpapers.jpg", "Dimensions"), " x ", 1)
$tile_width = $tile_dimension[1]
ConsoleWrite ( "$tile_width : " & $tile_width & @Crlf )
$tile_height = $tile_dimension[2]
ConsoleWrite ( "$tile_height : " & $tile_height & @Crlf )
$number_of_tiles = $tile_width/64
ConsoleWrite ( "$number_of_tiles : " & $number_of_tiles & @Crlf )

I get :

$tile_width : 1440

$tile_height : 900

$number_of_tiles : 22.5


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

When i try

#include <GetFileProperty.au3>

$tile_dimension = StringSplit(_GetFileProperty("D:\Wallpapers\041_abstract-wallpapers.jpg", "Dimensions"), " x ", 1)
$tile_width = $tile_dimension[1]
ConsoleWrite ( "$tile_width : " & $tile_width & @Crlf )
$tile_height = $tile_dimension[2]
ConsoleWrite ( "$tile_height : " & $tile_height & @Crlf )
$number_of_tiles = $tile_width/64
ConsoleWrite ( "$number_of_tiles : " & $number_of_tiles & @Crlf )

I get :

$tile_width : 1440

$tile_height : 900

$number_of_tiles : 22.5

Alright, I'll try updating again. :-\

Share this post


Link to post
Share on other sites

May be your pictures have no properties ?


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

May be your pictures have no properties ?

No like I said, I can return the strings properly as strings, so width will return the proper number, but if I try to do any math with what I get returned I get 0.

Hmm, maybe there are some issues with property format in Vista?

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Try number Function ! ( it returns the numeric representation of an expression )

#include <GetFileProperty.au3>

$tile_dimension = StringSplit(_GetFileProperty("D:\Wallpapers\041_abstract-wallpapers.jpg", "Dimensions"), " x ", 1)
$tile_width = Number ( $tile_dimension[1] )
$tile_height = Number ( $tile_dimension[2] )
$number_of_tiles = Number ( $tile_width/64 )
Edited by wakillon

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

Try number Function ! ( it returns the numeric representation of an expression )

#include <GetFileProperty.au3>

$tile_dimension = StringSplit(_GetFileProperty("D:\Wallpapers\041_abstract-wallpapers.jpg", "Dimensions"), " x ", 1)
$tile_width = Number ( $tile_dimension[1] )
$tile_height = Number ( $tile_dimension[2] )
$number_of_tiles = Number ( $tile_width/64 )

I've already tried int(str) and number(str) and neither work, infact when I try and output that directly to a MSG box I get 0. :unsure: This is making me a sad panda. I will try and write it out to a file and see if windows is adding creepy spaces and parse it all out.

Share this post


Link to post
Share on other sites

I've already tried int(str) and number(str) and neither work, infact when I try and output that directly to a MSG box I get 0. :unsure: This is making me a sad panda. I will try and write it out to a file and see if windows is adding creepy spaces and parse it all out.

YEP! So windows vista is outputting a weird character in front of the property so I'm going to have to parse that out, good thing is it's just one character so it's not going to be too difficult.

Share this post


Link to post
Share on other sites

I know the answer :unsure: Check here >>


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

If you need to get the dimension of a bitmap you can use GDI+ for example.

Here a simple function:

#include <GDIPlus.au3>
Local $file = FileOpenDialog("Select an image", "", "(*.jpg;*.png;*.bmp;*.gif)")
If @error Then Exit
Local $aDimension = Get_Image_Dimension($file)
If @error Then Exit MsgBox(16, "Error", "An error has occured!", 10)
MsgBox(0, "Image Dimension", "Filename: " & $file & @LF & @LF & _
                             "Image Dimension:" & @LF & @LF & _
                             "Width: " & @TAB & $aDimension[0] & @LF & _
                             "Height: " & @TAB & $aDimension[1]& @LF & _
                             "DPI: " & @TAB & $aDimension[2] & "x" & $aDimension[3], 30)
Exit

; #FUNCTION# =====================================================================================
; Name...........:      Get_Image_Dimension
; Description ...:  Returns the dimension of an image from a file
; Syntax.........:      Get_Image_Dimension($file)
; Parameters ....:  $file - filename of the image
; Return value ..:  Zero based array with the dimensions -> $iDim[0] = width, $iDim[1] = height, $iDim[2] = DPIx, $iDim[3] = DPIy
; Requirements ..:  GDIPlus.au3
; Author ........:      UEZ
; Version .......:      v0.60 build 2011-04-29 Beta
; ================================================================================================
Func Get_Image_Dimension($file)
    If Not FileExists($file) Then Return SetError(1, 0, False)
    Local $declared = 1, $iDim[4]
    If Not $ghGDIPDll Then
        _GDIPlus_Startup()
        $declared = 0
    EndIf
    Local $hImage = _GDIPlus_ImageLoadFromFile($file)
    Local $hContext = _GDIPlus_ImageGetGraphicsContext($hImage)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipGetImageDimension", "handle", $hImage, "float*", 0, "float*", 0)
    If @error Then Return SetError(@error, @extended, False)
    $iDim[0] = $aResult[2]
    $iDim[1] = $aResult[3]
    $aResult = DllCall($ghGDIPDll, "uint", "GdipGetDpiX", "handle", $hContext, "float*", 0)
    If @error Then Return SetError(@error, @extended, False)
    $iDim[2] = Round($aResult[2], 0)
    $aResult = DllCall($ghGDIPDll, "uint", "GdipGetDpiY", "handle", $hContext, "float*", 0)
        If @error Then Return SetError(@error, @extended, False)
    $iDim[3] = Round($aResult[2], 0)
    _GDIPlus_GraphicsDispose($hContext)
    _GDIPlus_ImageDispose($hImage)
    If Not $declared Then _GDIPlus_Shutdown()
    Return $iDim
EndFunc

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

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