Create Pixel Color

Get help with using AutoHotkey and its commands and hotkeys
User avatar
TheDewd
Posts: 1397
Joined: 19 Dec 2013, 11:16
Location: USA

Create Pixel Color

01 May 2015, 12:26

How can I create a 1x1 pixel image from either RGB or Hex color code?

I found this code below that generates a 3x1 gradient image. How can it be modified to only generate 1x1, single color?

I use this code for example because I like the simplicity. I've seen other GDI example code but there seems to be many more lines of code involved.

If you're curious, the 1x1 image would be used as a picture control in my Gui. It will be stretched to any size needed, helping to create backgrounds for different Gui design elements. I would like for the script itself to generate the images needed so that they would not need to be included with the script externally.

Code: Select all

GradientColorBand(151515)

GradientColorBand(RGB) { 
  file= ColorPicker_3x1.bmp
  StringMid,R,RGB,1,2
  StringMid,G,RGB,3,2
  StringMid,B,RGB,5,2

   Hs1:="424d42000000000000003600000028000000030000000100000001"
   Hs2:="001800000000000c00000000000000000000000000000000000000"
   Hs3:="FFFFFF" B G R "000000000000"

   HexString:= Hs1 Hs2 Hs3 

   Handle:= DllCall("CreateFile","str",file,"Uint",0x40000000
                ,"Uint",0,"UInt",0,"UInt",4,"Uint",0,"UInt",0) 

   Loop 66 { 
     StringLeft, Hex, HexString, 2         
     StringTrimLeft, HexString, HexString, 2  
     Hex = 0x%Hex%
     DllCall("WriteFile","UInt", Handle,"UChar *", Hex
     ,"UInt",1,"UInt *",UnusedVariable,"UInt",0) 
    } 
  
   DllCall("CloseHandle", "Uint", Handle)

Return File
}
Image Bulldozer - Sokoban inspired game from 1994 recreated in AutoHotkey.
User avatar
noname
Posts: 509
Joined: 19 Nov 2013, 09:15

Re: Create Pixel Color

01 May 2015, 14:07

Code: Select all

File= %a_scriptdir%\ColorPicker.bmp

GradientColorBand("ff80ff",file)
gui ,add,picture,w100 h100 ,%file%
gui,show
return



GradientColorBand(RGB,file) { 

 
   hex:="424D3A000000000000003600000028000000010000000100000001"
   . "0018000000000004000000130B0000130B"
   . "00000000000000000000" substr(RGB,5,2) substr(RGB,3,2) substr(RGB,1,2) "00"

file := FileOpen(File,"rw" )
Loop 58
    file.WriteUChar("0x" SubStr(hex,2*a_index-1,2))
File.Close()
Return 
}
soundcloud.com/user-32706894
User avatar
TheDewd
Posts: 1397
Joined: 19 Dec 2013, 11:16
Location: USA

Re: Create Pixel Color

31 Dec 2015, 13:55

I modified some of the code... Posting updated function here:

Code: Select all

CreatePixelBMP("ADFF5F", "Test.bmp") ; Example

CreatePixelBMP(C, Filename)
{
	BH := "424D3A0000000000000036000000280000000100000001000000"
	. "01001800000000000400000000000000000000000000000000000000"
	. SubStr(C, 5, 2) . SubStr(C, 3, 2) . SubStr(C, 1, 2) . "00"

	File := FileOpen(Filename, "rw")

	Loop, % StrLen(BH) // 2 {
		File.WriteUChar("0x" . SubStr(BH, (2 * A_Index) - 1, 2))
	}
	
	File.Close()
}
Image Bulldozer - Sokoban inspired game from 1994 recreated in AutoHotkey.
User avatar
TheDewd
Posts: 1397
Joined: 19 Dec 2013, 11:16
Location: USA

Re: Create Pixel Color

31 Dec 2015, 15:21

I modified the CreateDIB function by SKAN to create a single color using a HEX color code, and doesn't require saving to a file.

Code: Select all

#SingleInstance, Force

Gui, Add, Picture, % "x" 0 " y" 0 " w" 400 " h" 100 " +0x4E +HWNDhPicture1"
Gui, Add, Picture, % "x" 0 " y" 100 " w" 400 " h" 100 " +0x4E +HWNDhPicture2"
Gui, Add, Picture, % "x" 0 " y" 200 " w" 400 " h" 100 " +0x4E +HWNDhPicture3"
Gui, Add, Picture, % "x" 0 " y" 300 " w" 400 " h" 100 " +0x4E +HWNDhPicture4"

CreatePixel("FF0000", hPicture1) ; Red
CreatePixel("800080", hPicture2) ; Purple
CreatePixel("0000FF", hPicture3) ; Blue
CreatePixel("00FF00", hPicture4) ; Green

Gui, Show, % "w" 400 " h" 400, % "CreatePixel"
return

CreatePixel(Color, Handle) {
	VarSetCapacity(BMBITS, 4, 0), Numput("0x" . Color, &BMBITS, 0, "UInt")
	hBM := DllCall("Gdi32.dll\CreateBitmap", "Int", 1, "Int", 1, "UInt", 1, "UInt", 24, "Ptr", 0, "Ptr")
	hBM := DllCall("User32.dll\CopyImage", "Ptr", hBM, "UInt", 0, "Int", 0, "Int", 0, "UInt", 0x2008, "Ptr")
	DllCall("Gdi32.dll\SetBitmapBits", "Ptr", hBM, "UInt", 3, "Ptr", &BMBITS) 
	DllCall("User32.dll\SendMessage", "Ptr", Handle, "UInt", 0x172, "Ptr", 0, "Ptr", hBM)
}
Last edited by TheDewd on 11 Feb 2016, 16:34, edited 4 times in total.
Image Bulldozer - Sokoban inspired game from 1994 recreated in AutoHotkey.
User avatar
TheDewd
Posts: 1397
Joined: 19 Dec 2013, 11:16
Location: USA

Re: Create Pixel Color

17 Jan 2016, 01:37

Here's another similar function:

Code: Select all

#SingleInstance, Force

Gui, +LastFound -Resize +HwndGui1

Gui, Add, Picture, % "x" 0 " y" 0 " w" 400 " h" 100 " +0x4E +HWNDhPicture1"
Gui, Add, Picture, % "x" 0 " y" 100 " w" 400 " h" 100 " +0x4E +HWNDhPicture2"
Gui, Add, Picture, % "x" 0 " y" 200 " w" 400 " h" 100 " +0x4E +HWNDhPicture3"
Gui, Add, Picture, % "x" 0 " y" 300 " w" 400 " h" 100 " +0x4E +HWNDhPicture4"

CreatePixel2("FF0000", Gui1, hPicture1) ; Red
CreatePixel2("800080", Gui1, hPicture2) ; Purple
CreatePixel2("0000FF", Gui1, hPicture3) ; Blue
CreatePixel2("00FF00", Gui1, hPicture4) ; Green

Gui, Show, % "w" 400 " h" 400, % "CreatePixel"
Return

CreatePixel2(C, GuiHwnd, PicHwnd) {
	Global

	BMPH := "424D3A000000000000003600000028000000010000000100000"
	. "001001800000000000400000000000000000000000000000000000000"
	. SubStr(C, 5, 2) . SubStr(C, 3, 2) . SubStr(C, 1, 2) . "00"

	Loop, % VarSetCapacity(BMP, StrLen(BMPH)//2) {
		NumPut("0x" . SubStr(BMPH, (2*A_Index)-1, 2), BMP, A_Index-1, "Char")
	}

	BMPH := ""

	hBMP := DllCall("CreateDIBitmap", UInt, DllCall("GetDC", UInt, GuiHwnd), UInt
	, &BMP+14, UInt, 4, UInt, &BMP+NumGet(BMP, 10), UInt, &BMP+14, UInt, 1)
	hBMP2 := DllCall("CopyImage", UInt, hBMP, UInt, 0, Int, 200, Int, 200, UInt, 0)
	DllCall("DeleteObject", UInt, hBMP)
	SendMessage, 0x172, 0x0, hBMP2,, % "ahk_id " . PicHwnd
}
Image Bulldozer - Sokoban inspired game from 1994 recreated in AutoHotkey.
User avatar
TheDewd
Posts: 1397
Joined: 19 Dec 2013, 11:16
Location: USA

Re: Create Pixel Color

19 Jan 2016, 16:59

Code from SKAN to embed a PNG image using Base64 encoding... Took a while to find this.

Code: Select all

#SingleInstance, Force

PNGData=
(LTrim
	iVBORw0KGgoAAAANSUhEUgAAAPEAAABOCAMAAADGiQCbAAAAAXNSR0IArs4c6QAA
	AARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAadEVYdFNvZnR3
	YXJlAFBhaW50Lk5FVCB2My41LjEwMPRyoQAAAmRQTFRFAAAAAAAAAAAAACpVAAAA
	ACBAAAAAABkzAAAAABUqAAAAABIkAAAAABAgAA4cAAAAAA0ZAAAAAAwXAAAAAAAA
	AAoUAAAAAAAJwMXKw8jNw8rRAAAAAAgRurq7AAAAAAAAAAcPAAAAAAAAAAAAAAAA
	AAYGAAAAAAAAAAUL19jYAAAA0NTXAAAATE1NAAAASUlKxMfKxcbIsLCxAAAAsrOz
	AAAAOjo6OTk5AAAAAAAAYGBgWlpbXl5fX19gAAAAAAAAXFxdAAAAAAAAAAAAAAAC
	AAAARUVFR0dH4uLi5ufn5ufo19jZ4uPk2dnZ5+jp6Ojopqamr7CwpaWlqqqqnZ2d
	n5+fnZ2doKCgjY2Nj4+Q0NDQ3d3e3t/f4+TlpaWlsrKyoqKiq6urAAAADw8PHh4e
	LS0tLS0uOzs8PDw8SktLS0tMWVpaWlpbaGhpaWlqdnZ2dnd4d3h5eHh5hYWHhoeH
	iYmJjY2Nj4+PkZGRk5O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SOnZqn7Vu733hvZ6edI1Hs1/tcU4SaomUa3fFg4p0vRME/z2mvx2ofAt
	SQyOxAA6rOKDq1fr1rl2bc53e/PyotUqpQe51LV/q67oD+cUi9dOJ7wx8K3qdxLf
	Y97Xj7PS03rmGrTpfeW7/AY1o0bqtxEzbXjSa1vFwrOoUUWy4+AOKPLQe+89ilVK
	T3XwsIV4LCJTXjvwBErPajHo/H74/Tvoa1FktAp430oczPBMa1DAYMGiijzaDtVO
	9kREREBJrC09ofvvduK0l7cEQSlWJxQEjv4VNpZ3tmVsOhSpPDhuJza8lqDWmT0F
	74CTu5cvrCy6Yh4f1BOKkTqi8Q4ETu5uXAwXm147sHyk7YxXI04swO6uSXV6TTxr
	Hzea4g0gCYqOebC3ZzqEiKd4wWDt4RBBpNp0a3/Wwn12ZrE+0dqhMOmBDuJ6k2CA
	Z5Hhe+SmCrtOLXNEXsPbQxFZbg+ct739rJPN2kSNdRsZ6ycye8tF/tf/ZgK+t//+
	9aX0TvYyURymf/juN6poTc9Kr40Nm7w4daIHdY8fZGqhf3hJltL74CgrxrHfPvfn
	605mjQydmARs9evuZhbZwNbJ7idDAfz2uXfPfWXpvId/LzyHZt17+YNLLxV3Uc+6
	h5jTzrDyycGDf/S8Aln3Xn6xv7SeAcPa+sXnXGpNlUObN9tc4aJ+mB0f9Ae+6EpL
	7Rkgca7jzndMUsSci+9kRfKsm3XJir+x3J4pEl6pYdUUnxYP4vqQeYb5aCO/zF7V
	TVIM4ALzkJ68+MVxPaiW1zN1XtOQhCWnTJljkMk86bJ6ZuJ42C2UWTPk0nr/A8NI
	v5MkZVj5AAAAAElFTkSuQmCC
)

Bytes := Base64Decode(BIN, PNGDATA)
VarZ_Save(BIN, Bytes, "Example.png")
VarSetCapacity(PNGDATA, 0)

Gui, Add, Picture, % " x" 10 " y" 10 "w" 241 " h" 78, % "Example.png"
Gui, Show, % "w" 261 " h" 98, % "Example"
Return

Base64Decode(ByRef Output, ByRef Input) {
	DllCall("Crypt32.dll\CryptStringToBinary" (A_IsUnicode ? "W" : "A"), UInt, &Input, UInt, StrLen(Input), UInt, 1, UInt, 0, UIntP, Bytes, Int, 0, Int, 0, "CDECL Int")
	VarSetCapacity(Output, Req := Bytes * (A_IsUnicode ? 2 : 1))
	DllCall("Crypt32.dll\CryptStringToBinary" (A_IsUnicode ? "W" : "A"), UInt, &Input, UInt, StrLen(Input), UInt, 1, Str, Output, UIntP, Req, Int, 0, Int, 0, "CDECL Int")
	Return Bytes
}

VarZ_Save(ByRef Data, DataSize, TrgFile) {
	hFile := DllCall("Kernel32.dll\_lcreat", (A_IsUnicode ? "AStr" : "Str"), TrgFile, UInt, 0)
	IfLess, hFile, 1, Return "", ErrorLevel := 1
	nBytes := DllCall("Kernel32.dll\_lwrite", UInt, hFile, UInt, &Data, UInt, DataSize, UInt)
	DllCall("_lclose", UInt, hFile)
	Return nBytes
}
Image Bulldozer - Sokoban inspired game from 1994 recreated in AutoHotkey.
MrRED
Posts: 10
Joined: 19 May 2018, 21:15
Location: USA

Re: Create Pixel Color

19 May 2018, 22:14

Hello,

I modified CreatePixel function a while ago to address GDI objects leak caused when applying color to the same handle again and again.
Came across the function today and decided this is the time to pay back the community that I have been following many years without contribution.

I have a loop that changes the color of the picture pixel to make a flashing effect and each time the function was called - GDI objects were growing and sooner or later the 10,000 GDI objects limit has been reaching causing funky screen flickering.
Storing bitmap in a static variable and reusing the same bitmap has been an acceptable workaround that maintains a stable number of GDI objects no matter how long the flashing is happening.

If anyone knows how to keep the number of GDI objects stable without the use of static variable - please post your solution. Thanks

TheDewd, appreciate your functions.

P.S. I have tried CreatePixel2 functions and despite it is attempting to destroy objects - there is still GDI objects leak.

Code: Select all

CreatePixel(Color, Handle) {
	; 2015-12-31 TheDewd
	; 2018-03-02 MrRED
	; An improved CreatePixel function to keep track of previous Pixels and their Bitmaps
	; Reuse existing Bitmaps for the same Handle to prevent leaking GDI objects on reruns for the same handle
	static CreatePixelBitmapDB := {}

	if (CreatePixelBitmapDB[Handle])
		hBM := CreatePixelBitmapDB[Handle]
	else {
		hBM := DllCall("Gdi32.dll\CreateBitmap", "Int", 1, "Int", 1, "UInt", 1, "UInt", 24, "Ptr", 0, "Ptr")
		hBM := DllCall("User32.dll\CopyImage", "Ptr", hBM, "UInt", 0, "Int", 0, "Int", 0, "UInt", 0x2008, "Ptr")
		CreatePixelBitmapDB[Handle] := hBM
	}

	VarSetCapacity(BMBITS, 4, 0), Numput("0x" . Color, &BMBITS, 0, "UInt")
	DllCall("Gdi32.dll\SetBitmapBits", "Ptr", hBM, "UInt", 3, "Ptr", &BMBITS) 
	DllCall("User32.dll\SendMessage", "Ptr", Handle, "UInt", 0x172, "Ptr", 0, "Ptr", hBM)
}
User avatar
TheDewd
Posts: 1397
Joined: 19 Dec 2013, 11:16
Location: USA

Re: Create Pixel Color

12 Nov 2019, 11:30

@MrRED,

Actually, the function only needed a simple tweak to solve the high memory consumption issue.

The updated function is posted below:

Function:

Code: Select all

CreatePixel(HWND, Color) { ; TheDewd / 2019-11-12
	hBitmap := DllCall("Gdi32.dll\CreateBitmap", "Int", 1, "Int", 1, "UInt", 1, "UInt", 24, "Ptr", 0, "Ptr")
	hBM := DllCall("User32.dll\CopyImage", "Ptr", hBitmap, "UInt", 0, "Int", 0, "Int", 0, "UInt", 8, "Ptr")
	VarSetCapacity(BMBITS, 5, 0), Numput("0x" Color, &BMBITS, 0, "UInt")
	DllCall("Gdi32.dll\SetBitmapBits", "Ptr", hBM, "UInt", 4, "Ptr", &BMBITS)
	DllCall("User32.dll\SendMessage", "Ptr", HWND, "UInt", 0x0172, "Ptr", 0, "Ptr", hBM, "Ptr")
	DllCall("Gdi32.dll\DeleteObject", "Ptr", hBitmap)
}

Usage Example:

Code: Select all

#SingleInstance, Force
#Persistent

Gui, +LastFound -Resize +HWNDhCreatePixel

Gui, Add, Text, x0 y0 w300 h300 +0x4E HWNDhText1 ; Text control
Gui, Add, Picture, x+0 y0 w300 h300 +0x4E HWNDhPicture1 ; Picture control

CreatePixel(hText1, "FF00DC") ; Apply color to Text control
CreatePixel(hPicture1, "7AA4FF") ; Apply color to Picture control

Gui, Show, w600 h300, CreatePixel
return

GuiEscape:
GuiClose:
	ExitApp
return

CreatePixel(HWND, Color) { ; TheDewd / 2019-11-12
	hBitmap := DllCall("Gdi32.dll\CreateBitmap", "Int", 1, "Int", 1, "UInt", 1, "UInt", 24, "Ptr", 0, "Ptr")
	hBM := DllCall("User32.dll\CopyImage", "Ptr", hBitmap, "UInt", 0, "Int", 0, "Int", 0, "UInt", 8, "Ptr")
	VarSetCapacity(BMBITS, 5, 0), Numput("0x" Color, &BMBITS, 0, "UInt")
	DllCall("Gdi32.dll\SetBitmapBits", "Ptr", hBM, "UInt", 4, "Ptr", &BMBITS)
	DllCall("User32.dll\SendMessage", "Ptr", HWND, "UInt", 0x0172, "Ptr", 0, "Ptr", hBM, "Ptr")
	DllCall("Gdi32.dll\DeleteObject", "Ptr", hBitmap)
}
Image Bulldozer - Sokoban inspired game from 1994 recreated in AutoHotkey.
User avatar
boiler
Posts: 5563
Joined: 21 Dec 2014, 02:44

Re: Create Pixel Color

12 Nov 2019, 15:34

I use Progress controls for this purpose. The following looks equivalent in results to your example. Is there a reason this wouldn't suffice? I use them for big blocks of color as in your example, as well as for drawing lines with widths as small as a pixel.

Code: Select all

Gui, Add, Progress, x0 y0 w300 h300 BackgroundFF00DC
Gui, Add, Progress, x+0 y0 w300 h300 Background7AA4FF
Gui, Show, w600 h300, Progress Color
return

GuiClose:
ExitApp
User avatar
TheDewd
Posts: 1397
Joined: 19 Dec 2013, 11:16
Location: USA

Re: Create Pixel Color

12 Nov 2019, 15:41

boiler wrote:
12 Nov 2019, 15:34
I use Progress controls for this purpose. The following looks equivalent in results to your example. Is there a reason this wouldn't suffice? I use them for big blocks of color as in your example, as well as for drawing lines with widths as small as a pixel.

Code: Select all

Gui, Add, Progress, x0 y0 w300 h300 BackgroundFF00DC
Gui, Add, Progress, x+0 y0 w300 h300 Background7AA4FF
Gui, Show, w600 h300, Progress Color
return

GuiClose:
ExitApp
I can't remember the reason I stopped using Progress controls. I think the appearance looked different on older Windows OS (Windows XP?). I just wanted a solution that was consistent in appearance across various OS versions.

Maybe I'm mistaken though. I can't remember, and I don't have any Windows XP computers available for testing anymore.
Image Bulldozer - Sokoban inspired game from 1994 recreated in AutoHotkey.
User avatar
boiler
Posts: 5563
Joined: 21 Dec 2014, 02:44

Re: Create Pixel Color

12 Nov 2019, 15:46

That could be. I don't either. This might have the added advantage in that you can change the color of the control whenever you want without having to have one for each color.
User avatar
TheDewd
Posts: 1397
Joined: 19 Dec 2013, 11:16
Location: USA

Re: Create Pixel Color

12 Nov 2019, 16:00

boiler wrote:
12 Nov 2019, 15:46
This might have the added advantage in that you can change the color of the control whenever you want without having to have one for each color.

If you prefer using Progress controls, you can change the color on demand:

Code: Select all

#SingleInstance, Force

Colors := ["Red", "Green", "Blue", "Yellow", "Silver", "Olive"]

Gui, Add, Progress, x0 y0 w300 h300 vProg1 BackgroundFF00DC
Gui, Add, Progress, x+0 y0 w300 h300 vProg2 Background7AA4FF

Gui, Font, S16
Gui, Add, Text, x0 y0 w300 h300 vText1 0x201 +BackgroundTrans
Gui, Add, Text, x+0 y0 w300 h300 vText2 0x201 +BackgroundTrans

Gui, Show, w600 h300, Progress Color

SetTimer, ProgChange, 1000
return

ProgChange:
	Random, RandColor1, 1, 6
	Random, RandColor2, 1, 6
	GuiControl, % "+Background" Colors[RandColor1], Prog1
	GuiControl, % "+Background" Colors[RandColor2], Prog2
	GuiControl,, Text1, % Colors[RandColor1]
	GuiControl,, Text2, % Colors[RandColor2]
return

GuiEscape:
GuiClose:
	ExitApp
return
Image Bulldozer - Sokoban inspired game from 1994 recreated in AutoHotkey.
User avatar
boiler
Posts: 5563
Joined: 21 Dec 2014, 02:44

Re: Create Pixel Color

12 Nov 2019, 16:21

TheDewd wrote:
12 Nov 2019, 16:00
If you prefer using Progress controls, you can change the color on demand:
I may not have been clear, but that's what I meant. I was saying that is an advantage of using Progress controls for this purpose.

If you use a picture control, I believe there's no way around having to create another one for each color you want.
User avatar
TheDewd
Posts: 1397
Joined: 19 Dec 2013, 11:16
Location: USA

Re: Create Pixel Color

12 Nov 2019, 16:27

boiler wrote:
12 Nov 2019, 16:21
If you use a picture control, I believe there's no way around having to create another one for each color you want.
To change the color of an existing picture control, only need to use the function again with a different color code... CreatePixel(hText1, "FF00DC")

The function can be called multiple times for the same Picture or Text control.

Using the same HWND for each control created (instead of vVariable), you should be able to update the color for all at the same time.
Image Bulldozer - Sokoban inspired game from 1994 recreated in AutoHotkey.

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], Flipeador, Google [Bot], JoeWinograd and 42 guests