Jump to content

Building a bitmap from random color data?


Recommended Posts

Hello, I have been using autoit for a while now, and I have a code that generates some random hexadecimal data. I was wondering if it would be possible to build a bitmap of this? Like maybe make each pixel a different color based on the data. Like below?

color1->color2->color3->color4->color5

colorN->colorN->colorN->colorN->colorN

colorN->colorN->colorN->colorN->colorN

colorN->colorN->colorN->colorN->colorN

colorN->colorN->colorN->colorN->colorN

Link to comment
Share on other sites

Example

#include <GDIPlus.au3>

_GDIPlus_Startup()

;ARGB
Local $aColors[11]
For $i = 0 To UBound($aColors) - 1
$aColors[$i] = RandomColor()
Next

Main(50, $aColors, 50)

_GDIPlus_Shutdown()

Func RandomColor()
Return Random(0, 0xFFFFFF, 1)
EndFunc   ;==>RandomColor

Func Main($iRectWidth, $aColors, $iPixelLen)
If Not IsInt($iRectWidth) Then $iRectWidth = Int($iRectWidth)
Local $iWidth = (Floor($iRectWidth / 2) + Mod($iRectWidth, 2)) * $iPixelLen, $iHeight = Floor($iRectWidth / 2) * $iPixelLen
Local $hBmp = _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight), $hGfx = _GDIPlus_ImageGetGraphicsContext($hBmp)
Local $iUBound = UBound($aColors)
Local $aBrush = CreateArrayBrush($aColors)

Local $iBrush = 0
For $iY = 0 To $iHeight Step $iPixelLen
For $iX = 0 To $iWidth Step $iPixelLen
_GDIPlus_GraphicsFillRect($hGfx, $iX, $iY, $iPixelLen, $iPixelLen, $aBrush[$iBrush])
$iBrush += 1
If $iBrush = $iUBound Then $iBrush = 0
Next
Next

_GDIPlus_ImageSaveToFile($hBmp, @ScriptDir & "\Image.bmp")
ShellExecute(@ScriptDir & "\Image.bmp")

For $i = 0 To $iUBound - 1
_GDIPlus_BrushDispose($aBrush[$i])
Next
_GDIPlus_GraphicsDispose($hGfx)
_GDIPlus_ImageDispose($hBmp)
EndFunc   ;==>Main

;From GDIP library
Func _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight, $iStride = 0, $iPixelFormat = 0x0026200A, $pScan0 = 0)
Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iWidth, "int", $iHeight, "int", $iStride, "int", $iPixelFormat, "ptr", $pScan0, "int*", 0)

If @error Then Return SetError(@error, @extended, 0)
$GDIP_STATUS = $aResult[0]
Return $aResult[6]
EndFunc   ;==>_GDIPlus_BitmapCreateFromScan0

Func CreateArrayBrush($aColors)
Local $iUBound = UBound($aColors)
Local $aBrush[$iUBound]
For $i = 0 To $iUBound - 1
$aBrush[$i] = _GDIPlus_BrushCreateSolid(0xFF000000 + $aColors[$i])
Next
Return $aBrush
EndFunc   ;==>CreateArrayBrush

Randomised Brushes

#include <GDIPlus.au3>

_GDIPlus_Startup()

;ARGB
Local $aColors[11]
For $i = 0 To UBound($aColors) - 1
$aColors[$i] = RandomColor()
Next

Main(50, $aColors, 50)

_GDIPlus_Shutdown()

Func RandomColor()
Return Random(0, 0xFFFFFF, 1)
EndFunc   ;==>RandomColor

Func Main($iRectWidth, $aColors, $iPixelLen)
If Not IsInt($iRectWidth) Then $iRectWidth = Int($iRectWidth)
Local $iWidth = (Floor($iRectWidth / 2) + Mod($iRectWidth, 2)) * $iPixelLen, $iHeight = Floor($iRectWidth / 2) * $iPixelLen
Local $hBmp = _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight), $hGfx = _GDIPlus_ImageGetGraphicsContext($hBmp)
Local $iUBound = UBound($aColors)
Local $aBrush = CreateArrayBrush($aColors)

For $iY = 0 To $iHeight Step $iPixelLen
For $iX = 0 To $iWidth Step $iPixelLen
_GDIPlus_GraphicsFillRect($hGfx, $iX, $iY, $iPixelLen, $iPixelLen, $aBrush[Random(0, $iUBound - 1, 1)])
Next
Next

_GDIPlus_ImageSaveToFile($hBmp, @ScriptDir & "\Image.bmp")
ShellExecute(@ScriptDir & "\Image.bmp")

For $i = 0 To $iUBound - 1
_GDIPlus_BrushDispose($aBrush[$i])
Next
_GDIPlus_GraphicsDispose($hGfx)
_GDIPlus_ImageDispose($hBmp)
EndFunc   ;==>Main

;From GDIP library
Func _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight, $iStride = 0, $iPixelFormat = 0x0026200A, $pScan0 = 0)
Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iWidth, "int", $iHeight, "int", $iStride, "int", $iPixelFormat, "ptr", $pScan0, "int*", 0)

If @error Then Return SetError(@error, @extended, 0)
$GDIP_STATUS = $aResult[0]
Return $aResult[6]
EndFunc   ;==>_GDIPlus_BitmapCreateFromScan0

Func CreateArrayBrush($aColors)
Local $iUBound = UBound($aColors)
Local $aBrush[$iUBound]
For $i = 0 To $iUBound - 1
$aBrush[$i] = _GDIPlus_BrushCreateSolid(0xFF000000 + $aColors[$i])
Next
Return $aBrush
EndFunc   ;==>CreateArrayBrush

Regards :)

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

Example

#include <GDIPlus.au3>

_GDIPlus_Startup()

;ARGB
Local $aColors[11]
For $i = 0 To UBound($aColors) - 1
$aColors[$i] = RandomColor()
Next

Main(50, $aColors, 50)

_GDIPlus_Shutdown()

Func RandomColor()
Return Random(0, 0xFFFFFF, 1)
EndFunc ;==>RandomColor

Func Main($iRectWidth, $aColors, $iPixelLen)
If Not IsInt($iRectWidth) Then $iRectWidth = Int($iRectWidth)
Local $iWidth = (Floor($iRectWidth / 2) + Mod($iRectWidth, 2)) * $iPixelLen, $iHeight = Floor($iRectWidth / 2) * $iPixelLen
Local $hBmp = _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight), $hGfx = _GDIPlus_ImageGetGraphicsContext($hBmp)
Local $iUBound = UBound($aColors)
Local $aBrush = CreateArrayBrush($aColors)

Local $iBrush = 0
For $iY = 0 To $iHeight Step $iPixelLen
For $iX = 0 To $iWidth Step $iPixelLen
_GDIPlus_GraphicsFillRect($hGfx, $iX, $iY, $iPixelLen, $iPixelLen, $aBrush[$iBrush])
$iBrush += 1
If $iBrush = $iUBound Then $iBrush = 0
Next
Next

_GDIPlus_ImageSaveToFile($hBmp, @ScriptDir & "\Image.bmp")
ShellExecute(@ScriptDir & "\Image.bmp")

For $i = 0 To $iUBound - 1
_GDIPlus_BrushDispose($aBrush[$i])
Next
_GDIPlus_GraphicsDispose($hGfx)
_GDIPlus_ImageDispose($hBmp)
EndFunc ;==>Main

;From GDIP library
Func _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight, $iStride = 0, $iPixelFormat = 0x0026200A, $pScan0 = 0)
Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iWidth, "int", $iHeight, "int", $iStride, "int", $iPixelFormat, "ptr", $pScan0, "int*", 0)

If @error Then Return SetError(@error, @extended, 0)
$GDIP_STATUS = $aResult[0]
Return $aResult[6]
EndFunc ;==>_GDIPlus_BitmapCreateFromScan0

Func CreateArrayBrush($aColors)
Local $iUBound = UBound($aColors)
Local $aBrush[$iUBound]
For $i = 0 To $iUBound - 1
$aBrush[$i] = _GDIPlus_BrushCreateSolid(0xFF000000 + $aColors[$i])
Next
Return $aBrush
EndFunc ;==>CreateArrayBrush

Randomised Brushes

#include <GDIPlus.au3>

_GDIPlus_Startup()

;ARGB
Local $aColors[11]
For $i = 0 To UBound($aColors) - 1
$aColors[$i] = RandomColor()
Next

Main(50, $aColors, 50)

_GDIPlus_Shutdown()

Func RandomColor()
Return Random(0, 0xFFFFFF, 1)
EndFunc ;==>RandomColor

Func Main($iRectWidth, $aColors, $iPixelLen)
If Not IsInt($iRectWidth) Then $iRectWidth = Int($iRectWidth)
Local $iWidth = (Floor($iRectWidth / 2) + Mod($iRectWidth, 2)) * $iPixelLen, $iHeight = Floor($iRectWidth / 2) * $iPixelLen
Local $hBmp = _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight), $hGfx = _GDIPlus_ImageGetGraphicsContext($hBmp)
Local $iUBound = UBound($aColors)
Local $aBrush = CreateArrayBrush($aColors)

For $iY = 0 To $iHeight Step $iPixelLen
For $iX = 0 To $iWidth Step $iPixelLen
_GDIPlus_GraphicsFillRect($hGfx, $iX, $iY, $iPixelLen, $iPixelLen, $aBrush[Random(0, $iUBound - 1, 1)])
Next
Next

_GDIPlus_ImageSaveToFile($hBmp, @ScriptDir & "\Image.bmp")
ShellExecute(@ScriptDir & "\Image.bmp")

For $i = 0 To $iUBound - 1
_GDIPlus_BrushDispose($aBrush[$i])
Next
_GDIPlus_GraphicsDispose($hGfx)
_GDIPlus_ImageDispose($hBmp)
EndFunc ;==>Main

;From GDIP library
Func _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight, $iStride = 0, $iPixelFormat = 0x0026200A, $pScan0 = 0)
Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iWidth, "int", $iHeight, "int", $iStride, "int", $iPixelFormat, "ptr", $pScan0, "int*", 0)

If @error Then Return SetError(@error, @extended, 0)
$GDIP_STATUS = $aResult[0]
Return $aResult[6]
EndFunc ;==>_GDIPlus_BitmapCreateFromScan0

Func CreateArrayBrush($aColors)
Local $iUBound = UBound($aColors)
Local $aBrush[$iUBound]
For $i = 0 To $iUBound - 1
$aBrush[$i] = _GDIPlus_BrushCreateSolid(0xFF000000 + $aColors[$i])
Next
Return $aBrush
EndFunc ;==>CreateArrayBrush

Regards :)

Thanks so much, this is perfect.

Edit: just one question I looked through the _GDIPlus_ functions, but couldn't seem to find a way to place the result directly on an image control, am I missing something, or would I have to save it to a file first, then load it to the control?

Edited by nullschritt
Link to comment
Share on other sites

Here we go

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <Constants.au3>

_GDIPlus_Startup()

Global Const $STM_SETIMAGE = 0x0172

;ARGB
Local $aColors[11]
For $i = 0 To UBound($aColors) - 1
$aColors[$i] = RandomColor()
Next

$iPic = CreateGUI()
Main(50, $aColors, 50, $iPic)

GUISetState()

While GUIGetMsg() <> $GUI_EVENT_CLOSE
Sleep(10)
WEnd

GUIDelete()

_GDIPlus_Shutdown()

Func RandomColor()
Return Random(0, 0xFFFFFF, 1)
EndFunc ;==>RandomColor

Func CreateGUI()
GUICreate(StringTrimRight(@ScriptName, 4), 600, 400)
$iPic = GUICtrlCreatePic('', 0, 0, 600, 400, $SS_BITMAP)
Return $iPic
EndFunc ;==>CreateGUI

Func Main($iRectWidth, $aColors, $iPixelLen, $iPic)
If Not IsInt($iRectWidth) Then $iRectWidth = Int($iRectWidth)
Local $iWidth = (Floor($iRectWidth / 2) + Mod($iRectWidth, 2)) * $iPixelLen, $iHeight = Floor($iRectWidth / 2) * $iPixelLen
Local $hBmp = _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight), $hGfx = _GDIPlus_ImageGetGraphicsContext($hBmp)
Local $iUBound = UBound($aColors)
Local $aBrush = CreateArrayBrush($aColors)

Local $iBrush = 0
For $iY = 0 To $iHeight Step $iPixelLen
For $iX = 0 To $iWidth Step $iPixelLen
_GDIPlus_GraphicsFillRect($hGfx, $iX, $iY, $iPixelLen, $iPixelLen, $aBrush[$iBrush])
$iBrush += 1
If $iBrush = $iUBound Then $iBrush = 0
Next
Next

;Image Controls Accept HBitmap Objects
$hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap( $hBmp )
GUICtrlSendMsg( $iPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBitmap)

;Memory Release
_WinAPI_DeleteObject($hHBitmap)
For $i = 0 To $iUBound - 1
_GDIPlus_BrushDispose($aBrush[$i])
Next
_GDIPlus_GraphicsDispose($hGfx)
_GDIPlus_ImageDispose($hBmp)
EndFunc ;==>Main

;From GDIP library
Func _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight, $iStride = 0, $iPixelFormat = 0x0026200A, $pScan0 = 0)
Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iWidth, "int", $iHeight, "int", $iStride, "int", $iPixelFormat, "ptr", $pScan0, "int*", 0)

If @error Then Return SetError(@error, @extended, 0)
$GDIP_STATUS = $aResult[0]
Return $aResult[6]
EndFunc ;==>_GDIPlus_BitmapCreateFromScan0

Func CreateArrayBrush($aColors)
Local $iUBound = UBound($aColors)
Local $aBrush[$iUBound]
For $i = 0 To $iUBound - 1
$aBrush[$i] = _GDIPlus_BrushCreateSolid(0xFF000000 + $aColors[$i])
Next
Return $aBrush
EndFunc ;==>CreateArrayBrush
Thumbs up if it helped

Regards :)

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

Thanks, having one small hiccup, I don't know if it is because I am too sleep deprived to see the answer.

I modified to code to read the colors from a file, the file contains multpule sets of colors, and I am trying to base the image off of them, however I get an invalid array error when I try to put the array through the function

>"C:Program Files (x86)AutoIt3SciTE..autoit3.exe" /ErrorStdOut "C:UsersnullschrittDesktopbitmap.au3"

C:UsersnullschrittDesktopbitmap.au3 (19) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

Main(150, $aColors[$i], 4)

Main(150, ^ ERROR

>Exit code: 1 Time: 2.626

The Code:

#include <GDIPlus.au3>
#include <array.au3>
_GDIPlus_Startup()
;ARGB
$colors = "colors.txt"
$data = FileRead($colors)
$datax = StringSplit($data, "~")
dim $acolors[$datax[0]][500]
for $i=1 to $datax[0]-1
$aColorsx = _Stringequalsplit(StringTrimLeft($datax[$i],3), 6)
For $i2 = 0 To UBound($aColorsx) - 1
$aColors[$i][$i2] = "0x"&$aColorsx[$i2]
Next
Next
for $i=1 to $datax[0]-1
Main(150, $aColors[$i], 4)
Next
_GDIPlus_Shutdown()
Func RandomColor()
Return Random(0, 0xFFFFFF, 1)
EndFunc ;==>RandomColor
Func Main($iRectWidth, $aColors, $iPixelLen)
If Not IsInt($iRectWidth) Then $iRectWidth = Int($iRectWidth)
Local $iWidth = (Floor($iRectWidth / 2) + Mod($iRectWidth, 2)) * $iPixelLen, $iHeight = Floor($iRectWidth / 2) * $iPixelLen
Local $hBmp = _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight), $hGfx = _GDIPlus_ImageGetGraphicsContext($hBmp)
Local $iUBound = UBound($aColors)
Local $aBrush = CreateArrayBrush($aColors)
For $iY = 0 To $iHeight Step $iPixelLen
For $iX = 0 To $iWidth Step $iPixelLen
_GDIPlus_GraphicsFillRect($hGfx, $iX, $iY, $iPixelLen, $iPixelLen, $aBrush[Random(0, $iUBound - 1, 1)])
Next
Next
_GDIPlus_ImageSaveToFile($hBmp, @ScriptDir & "\Image.bmp")
ShellExecute(@ScriptDir & "\Image.bmp")
For $i = 0 To $iUBound - 1
_GDIPlus_BrushDispose($aBrush[$i])
Next
_GDIPlus_GraphicsDispose($hGfx)
_GDIPlus_ImageDispose($hBmp)
EndFunc ;==>Main
;From GDIP library
Func _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight, $iStride = 0, $iPixelFormat = 0x0026200A, $pScan0 = 0)
Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iWidth, "int", $iHeight, "int", $iStride, "int", $iPixelFormat, "ptr", $pScan0, "int*", 0)
If @error Then Return SetError(@error, @extended, 0)
$GDIP_STATUS = $aResult[0]
Return $aResult[6]
EndFunc ;==>_GDIPlus_BitmapCreateFromScan0
Func CreateArrayBrush($aColors)
Local $iUBound = UBound($aColors)
Local $aBrush[$iUBound]
For $i = 0 To $iUBound - 1
$aBrush[$i] = _GDIPlus_BrushCreateSolid(0xFF000000 + $aColors[$i])
Next
Return $aBrush
EndFunc ;==>CreateArrayBrush
Func _StringEqualSplit($sString, $iNumChars)
If (Not IsString($sString)) Or $sString = "" Then Return SetError(1, 0, 0)
If (Not IsInt($iNumChars)) Or $iNumChars < 1 Then Return SetError(2, 0, 0)
Return StringRegExp($sString, "(?s).{1," & $iNumChars & "}", 3)
EndFunc

Example File

0x0147AD030000DD04000000000080312E3031323930393436353035383638652B3035332C312E3632353438343840002080343234393837768632363031373735303830373736397686303434353433313339200002D0303537313277863139303238383535323436B8163539363132353034393971AA36768604900081323211BB30353639383336323476863134211A3830313531353237E4782F342E3830330004208232313733363334353231E378342C372E373038313437B271323730F378342C352E39000900A0373539313132333961B531337286342C342E39353239323536323736373138577838C9008080011236332161363171617486372E35363839323032333335353030E578352E3739383936005206823236393730363737317486352E71213511BB323362174378342F312E3934123139383137380262448633E378332C332E313136621733343131247378332C32D173363133B1713638114B77783030323701232084214434363930373535728612F2393533B130363436363439371578332E3036311037323833067000983721620578322E333434363239310172511AE578322E31383831393330373435520273862F32E02170C82E3033363621A06117B1A1E578332E3236B101343134333835A1B27386F10C353333381163303061371620A0A130537812F13132313737323539393139787834383937383933B12738757811D130393239B1B231188800E4383639162601D735383833393651A33932383578322E3239343736363339A1343839E478C23C63CA05EBA360B10438363356F612D1323171513031473038257801D7B11631512134313637355778316437715A36113151B1B325A38376863234383531A1012032E478F21C347202353211273036757801D7303930715A3141AB3164768632343833301AC237AF3421BB36413524782F332E36014236323135316B21A0728662F6B105362132A2BA3836137862F76117A10338115B355C3037B737324478F11C4163367121323034323626E611D53539312131A1514637037862F637332116611B411137B43662F73310230FBC3931303431B237303001767486342E30A14B3132B216412B1478C13C32333233383841BA610B2846A1443793F304B3711572AA34327578312E61001153A1033436214A728612F21143383871563438303438037813F23339B1753177392F23E2B30172F37812F2A2713061A534324166E578312E34B14B3635374135393633437812F201BB51B4B10A3336310573867C000000807B507542724EA650754E61436F48657D~0x0147AD030000DD04000000000080312E3031323930393436353035383638652B3035332C312E3632353438343840002080343234393837768632363031373735303830373736397686303434353433313339200002D0303537313277863139303238383535323436B8163539363132353034393971AA36768604900081323211BB30353639383336323476863134211A3830313531353237E4782F342E3830330004208232313733363334353231E378342C372E373038313437B271323730F378342C352E39000900A0373539313132333961B531337286342C342E39353239323536323736373138577838C9008080011236332161363171617486372E35363839323032333335353030E578352E3739383936005206823236393730363737317486352E71213511BB323362174378342F312E3934123139383137380262448633E378332C332E313136621733343131247378332C32D173363133B1713638114B77783030323701232084214434363930373535728612F2393533B130363436363439371578332E3036311037323833067000983721620578322E333434363239310172511AE578322E31383831393330373435520273862F32E02170C82E3033363621A06117B1A1E578332E3236B101343134333835A1B27386F10C353333381163303061371620A0A130537812F13132313737323539393139787834383937383933B12738757811D130393239B1B231188800E4383639162601D735383833393651A33932383578322E3239343736363339A1343839E478C23C63CA05EBA360B10438363356F612D1323171513031473038257801D7B11631512134313637355778316437715A36113151B1B325A38376863234383531A1012032E478F21C347202353211273036757801D7303930715A3141AB3164768632343833301AC237AF3421BB36413524782F332E36014236323135316B21A0728662F6B105362132A2BA3836137862F76117A10338115B355C3037B737324478F11C4163367121323034323626E611D53539312131A1514637037862F637332116611B411137B43662F73310230FBC3931303431B237303001767486342E30A14B3132B216412B1478C13C32333233383841BA610B2846A1443793F304B3711572AA34327578312E61001153A1033436214A728612F21143383871563438303438037813F23339B1753177392F23E2B30172F37812F2A2713061A534324166E578312E34B14B3635374135393633437812F201BB51B4B10A3336310573867C000000807B507542724EA650754E61436F48657D~0x0147AD030000DD04000000000080312E3031323930393436353035383638652B3035332C312E3632353438343840002080343234393837768632363031373735303830373736397686303434353433313339200002D0303537313277863139303238383535323436B8163539363132353034393971AA36768604900081323211BB30353639383336323476863134211A3830313531353237E4782F342E3830330004208232313733363334353231E378342C372E373038313437B271323730F378342C352E39000900A0373539313132333961B531337286342C342E39353239323536323736373138577838C9008080011236332161363171617486372E35363839323032333335353030E578352E3739383936005206823236393730363737317486352E71213511BB323362174378342F312E3934123139383137380262448633E378332C332E313136621733343131247378332C32D173363133B1713638114B77783030323701232084214434363930373535728612F2393533B130363436363439371578332E3036311037323833067000983721620578322E333434363239310172511AE578322E31383831393330373435520273862F32E02170C82E3033363621A06117B1A1E578332E3236B101343134333835A1B27386F10C353333381163303061371620A0A130537812F13132313737323539393139787834383937383933B12738757811D130393239B1B231188800E4383639162601D735383833393651A33932383578322E3239343736363339A1343839E478C23C63CA05EBA360B10438363356F612D1323171513031473038257801D7B11631512134313637355778316437715A36113151B1B325A38376863234383531A1012032E478F21C347202353211273036757801D7303930715A3141AB3164768632343833301AC237AF3421BB36413524782F332E36014236323135316B21A0728662F6B105362132A2BA3836137862F76117A10338115B355C3037B737324478F11C4163367121323034323626E611D53539312131A1514637037862F637332116611B411137B43662F73310230FBC3931303431B237303001767486342E30A14B3132B216412B1478C13C32333233383841BA610B2846A1443793F304B3711572AA34327578312E61001153A1033436214A728612F21143383871563438303438037813F23339B1753177392F23E2B30172F37812F2A2713061A534324166E578312E34B14B3635374135393633437812F201BB51B4B10A3336310573867C000000807B507542724EA650754E61436F48657D~0x0147AD030000DD04000000000080312E3031323930393436353035383638652B3035332C312E3632353438343840002080343234393837768632363031373735303830373736397686303434353433313339200002D0303537313277863139303238383535323436B8163539363132353034393971AA36768604900081323211BB30353639383336323476863134211A3830313531353237E4782F342E3830330004208232313733363334353231E378342C372E373038313437B271323730F378342C352E39000900A0373539313132333961B531337286342C342E39353239323536323736373138577838C9008080011236332161363171617486372E35363839323032333335353030E578352E3739383936005206823236393730363737317486352E71213511BB323362174378342F312E3934123139383137380262448633E378332C332E313136621733343131247378332C32D173363133B1713638114B77783030323701232084214434363930373535728612F2393533B130363436363439371578332E3036311037323833067000983721620578322E333434363239310172511AE578322E31383831393330373435520273862F32E02170C82E3033363621A06117B1A1E578332E3236B101343134333835A1B27386F10C353333381163303061371620A0A130537812F13132313737323539393139787834383937383933B12738757811D130393239B1B231188800E4383639162601D735383833393651A33932383578322E3239343736363339A1343839E478C23C63CA05EBA360B10438363356F612D1323171513031473038257801D7B11631512134313637355778316437715A36113151B1B325A38376863234383531A1012032E478F21C347202353211273036757801D7303930715A3141AB3164768632343833301AC237AF3421BB36413524782F332E36014236323135316B21A0728662F6B105362132A2BA3836137862F76117A10338115B355C3037B737324478F11C4163367121323034323626E611D53539312131A1514637037862F637332116611B411137B43662F73310230FBC3931303431B237303001767486342E30A14B3132B216412B1478C13C32333233383841BA610B2846A1443793F304B3711572AA34327578312E61001153A1033436214A728612F21143383871563438303438037813F23339B1753177392F23E2B30172F37812F2A2713061A534324166E578312E34B14B3635374135393633437812F201BB51B4B10A3336310573867C000000807B507542724EA650754E61436F48657D~0x0147AD030000DD04000000000080312E3031323930393436353035383638652B3035332C312E3632353438343840002080343234393837768632363031373735303830373736397686303434353433313339200002D0303537313277863139303238383535323436B8163539363132353034393971AA36768604900081323211BB30353639383336323476863134211A3830313531353237E4782F342E3830330004208232313733363334353231E378342C372E373038313437B271323730F378342C352E39000900A0373539313132333961B531337286342C342E39353239323536323736373138577838C9008080011236332161363171617486372E35363839323032333335353030E578352E3739383936005206823236393730363737317486352E71213511BB323362174378342F312E3934123139383137380262448633E378332C332E313136621733343131247378332C32D173363133B1713638114B77783030323701232084214434363930373535728612F2393533B130363436363439371578332E3036311037323833067000983721620578322E333434363239310172511AE578322E31383831393330373435520273862F32E02170C82E3033363621A06117B1A1E578332E3236B101343134333835A1B27386F10C353333381163303061371620A0A130537812F13132313737323539393139787834383937383933B12738757811D130393239B1B231188800E4383639162601D735383833393651A33932383578322E3239343736363339A1343839E478C23C63CA05EBA360B10438363356F612D1323171513031473038257801D7B11631512134313637355778316437715A36113151B1B325A38376863234383531A1012032E478F21C347202353211273036757801D7303930715A3141AB3164768632343833301AC237AF3421BB36413524782F332E36014236323135316B21A0728662F6B105362132A2BA3836137862F76117A10338115B355C3037B737324478F11C4163367121323034323626E611D53539312131A1514637037862F637332116611B411137B43662F73310230FBC3931303431B237303001767486342E30A14B3132B216412B1478C13C32333233383841BA610B2846A1443793F304B3711572AA34327578312E61001153A1033436214A728612F21143383871563438303438037813F23339B1753177392F23E2B30172F37812F2A2713061A534324166E578312E34B14B3635374135393633437812F201BB51B4B10A3336310573867C000000807B507542724EA650754E61436F48657D~
Edited by nullschritt
Link to comment
Share on other sites

  • Moderators

nullschritt,

I think trancexx's code here might be of interest to you. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

You cannot pass a 2D array with a 1Dimension and expect it to be an Array.

For $aRRay[$i][$i2] you have to pass both the values of the dimensions that is the first dimension and the second dimension.

Furthermore if you pass $aRRay[$i] it will cause an error and simultaneously its not an Array..

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

I'm assuming the text you provided is the file Colors.txt in the scriptdir. You can use something like this

#include <GDIPlus.au3>
#include <array.au3>

_GDIPlus_Startup()

;ARGB
$data = FileRead("colors.txt")
$data = StringSplit($data, "~0x0")
Local $aColors[1], $aTemp

For $i = 1 To $data[0]
$aTemp = _Stringequalsplit($data[$i], 6)
For $n = 0 To UBound($aTemp) - 1
_ArrayAdd($aColors, Number("0x" & $aTemp[$n]))
Next
Next
;~ _ArrayDisplay($aColors)

Main(150, $aColors, 4)
_GDIPlus_Shutdown()

Func RandomColor()
Return Random(0, 0xFFFFFF, 1)
EndFunc   ;==>RandomColor

Func Main($iRectWidth, $aColors, $iPixelLen)
If Not IsInt($iRectWidth) Then $iRectWidth = Int($iRectWidth)
Local $iWidth = (Floor($iRectWidth / 2) + Mod($iRectWidth, 2)) * $iPixelLen, $iHeight = Floor($iRectWidth / 2) * $iPixelLen
Local $hBmp = _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight), $hGfx = _GDIPlus_ImageGetGraphicsContext($hBmp)
Local $iUBound = UBound($aColors)
Local $aBrush = CreateArrayBrush($aColors)
For $iY = 0 To $iHeight Step $iPixelLen
For $iX = 0 To $iWidth Step $iPixelLen
_GDIPlus_GraphicsFillRect($hGfx, $iX, $iY, $iPixelLen, $iPixelLen, $aBrush[Random(0, $iUBound - 1, 1)])
Next
Next
_GDIPlus_ImageSaveToFile($hBmp, @ScriptDir & "\Image.bmp")
ShellExecute(@ScriptDir & "\Image.bmp")
For $i = 0 To $iUBound - 1
_GDIPlus_BrushDispose($aBrush[$i])
Next
_GDIPlus_GraphicsDispose($hGfx)
_GDIPlus_ImageDispose($hBmp)
EndFunc   ;==>Main

;From GDIP library
Func _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight, $iStride = 0, $iPixelFormat = 0x0026200A, $pScan0 = 0)
Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iWidth, "int", $iHeight, "int", $iStride, "int", $iPixelFormat, "ptr", $pScan0, "int*", 0)
If @error Then Return SetError(@error, @extended, 0)
$GDIP_STATUS = $aResult[0]
Return $aResult[6]
EndFunc   ;==>_GDIPlus_BitmapCreateFromScan0

Func CreateArrayBrush($aColors)
Local $iUBound = UBound($aColors)
Local $aBrush[$iUBound]
For $i = 0 To $iUBound - 1
$aBrush[$i] = _GDIPlus_BrushCreateSolid(0xFF000000 + $aColors[$i])
Next
Return $aBrush
EndFunc   ;==>CreateArrayBrush

Func _StringEqualSplit($sString, $iNumChars)
If (Not IsString($sString)) Or $sString = "" Then Return SetError(1, 0, 0)
If (Not IsInt($iNumChars)) Or $iNumChars < 1 Then Return SetError(2, 0, 0)
Return StringRegExp($sString, "(?s).{1," & $iNumChars & "}", 3)
EndFunc   ;==>_StringEqualSplit
Hope this helps :)

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

Thanks for all your help, if I am correct, the image repeats the data until ti fills the object? Does this mean it would not be possible to get back the original value of the data (each color, and reconstruct it into the string)? I saw a similar UDF for this, but it writes the data in one long column, which is hard to print out on one sheet of paper and still maintain all the detail.

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...