Jump to content

Colors


Recommended Posts

hy guys...

i want to make a something like this : http://i.minus.com/jbs9Le4vueZnWP.jpg

in GDI+ or WinApi (random generate a colors into a image)

Image size : 200x200

square size : 10x10

colors : all (random)

ps. sorry for my english

Link to comment
Share on other sites

You can certainly do it with GDI+ or other methods, and, not knowing what your requirements are, maybe you need to go that route. There are likely a bunch of tic-tac-toe/checkers/chess type board games in the examples forum that would have something you could use. Probably the easiest way to just recreate that image would be with labels and background colors:

Global $square[11][11]
Global $color[5] = [0x000000, 0xFF0000, 0x00FF00, 0x0000FF, 0xFFFFFF]

GUICreate("", 240, 240)
For $x = 1 to 10
    For $y = 1 to 10
        $square[$x][$y] = GUICtrlCreateLabel("", $x * 20, $y * 20, 20, 20)
        GUICtrlSetBkColor(-1, $color[Random(0, 4, 1)])
    Next
Next
GUISetState()
Sleep(5000)
Edited by Spiff59
Link to comment
Share on other sites

Herez The Code:

U can Create Mulitple Such Things As Per Your Needs..

#include <GDIPlus.au3>
#include <ScreenCapture.au3>
#include <WinAPI.au3>
Opt('MustDeclareVars', 1)
_Main()
Func _Main()
Local $hGraphics,$x,$y
; Initialize GDI+ library
;_GDIPlus_Startup ()
GUICreate('',500,700,50,50)
GUISetState()
; Draw one image in another
; Draw a frame around the inserted image
;_GDIPlus_GraphicsDrawRect ($hGraphics, 100, 100, 400, 300)
Local $sMsg
While $sMsg<>-3
  $sMsg=GUIGetMsg()
  $hGraphics = GUICtrlCreateLabel('',10,10,100,100)
  _GUICtrlSetBkColor($hGraphics)
  Sleep(100)
WEnd
GUIDelete()
; Shut down GDI+ library
;_GDIPlus_ShutDown ()
EndFunc   ;==>_Main
Func _GUICtrlSetBkColor($sControlID)
;Get Random Color
Local $sRed=_RandomizeHex()
Local $sGreen=_RandomizeHex()
Local $sBlue=_RandomizeHex()
Local $sRGB=$sRed&$sGreen&$sBlue
;ConsoleWrite('RGB:'&$sRGB&@CRLF)
Return GUICtrlSetBkColor($sControlID,$sRGB)
EndFunc
Func _RandomizeHex()
Local $sData="abcdef0123456789"
Local $sValues=StringSplit($sData,'',1)
Local $sRandom= Random(1,$sValues[0],1)
Local $hRandom=Random(1,$sValues[0],1)
Return $sValues[$sRandom]&$sValues[$hRandom]
EndFunc

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

Hi,

#include <GDIPlus.au3>
#include <WinAPI.au3>

Global $sSaveImage = @ScriptDir & "Colors.jpg"
Global $iImageSize = 200, $iSquareSize = 10
Global $hBMP, $hImage, $hGraphic, $hBrush, $iX = 0, $iY = 0

_GDIPlus_Startup()

$hBMP = _WinAPI_CreateBitmap($iImageSize, $iImageSize, 1, 32)
$hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBMP)
$hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage)
$hBrush = _GDIPlus_BrushCreateSolid()
For $i = 1 To ($iImageSize * $iImageSize) Step $iSquareSize
    _GDIPlus_BrushSetSolidColor($hBrush, Random(0xFF000000, 0xFFFFFFFF, 1))
    _GDIPlus_GraphicsFillRect($hGraphic, $iX, $iY, $iSquareSize, $iSquareSize, $hBrush)
    If $iX >= $iImageSize Then
        $iX = 0
        $iY += $iSquareSize
    Else
        $iX += $iSquareSize
    EndIf
Next
_GDIPlus_ImageSaveToFile($hImage, $sSaveImage)

_WinAPI_DeleteObject($hBMP)
_GDIPlus_BrushDispose($hBrush)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_ImageDispose($hImage)

_GDIPlus_Shutdown()

If FileExists($sSaveImage) Then ShellExecute($sSaveImage)

Edited by smashly
Link to comment
Share on other sites

thank you all

just one more question ...

now i want to read from this file RGB color from some coord in my file

ex:
File : colors.jpg
Read color from : x = 10; y = 40

Thanks in advance.

Edited by PlayHD
Link to comment
Share on other sites

Code:

#include <GDIPlus.au3>
Opt("MustDeclareVars", 1)
_Main()
Func _Main()
Local $hBmp, $hBitmap, $iColor
; Initialize GDI+
_GDIPlus_Startup()
$hBmp = 'Scroll Bar.png' ;Your Image File
; Create GDI+ Bitmap object from GDI Bitmap object
$hBitmap = _GDIPlus_BitmapCreateFromFile($hBmp)
If $hBitmap=0 Then Return MsgBox(16,'Color','File Not Found or is not Supported')
$iColor = _GDIPlus_BitmapGetPixel($hBitmap, 10,40)
If $iColor = -1 Then Return MsgBox(16,'Color','Something Went Wrong with the GDIPlus')
MsgBox(64, "Color", "Bitmap Pixel Color at [10, 40] is: 0x" & Hex($iColor))
; Clean up
_GDIPlus_ImageDispose($hBitmap)
; Uninitialize GDI+
_GDIPlus_Shutdown()
EndFunc
Func _GDIPlus_BitmapGetPixel($hFile, $x, $y)
Local $aResult = DllCall($ghGDIPDll, "uint", "GdipBitmapGetPixel", "hwnd", $hFile, "int", $x, "int", $y, "uint*", 0)
If @error Then Return SetError(1, @extended, -1)
Return $aResult[4]
EndFunc   ;==>_GDIPlus_BitmapGetPixel

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

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