CreateDIB() : Create hBitmap with series of RRGGBB hex values.

Post your working scripts, libraries and tools
User avatar
SKAN
Posts: 612
Joined: 29 Sep 2013, 16:58

CreateDIB() : Create hBitmap with series of RRGGBB hex values.

01 Apr 2014, 08:29

CreateDIB( PixelData, W, H, ResizeW, ResizeH, Gradient, DIB )

Parametes:
PixelData : Series of RRGGBB values delimited with Pipe "|".
W,H : The dimension of the image in PixelData.
ResizeW, ResizeH : The resized dimensions if image needs to be upscaled.
Gradient : Default value false. If true, image will be upscaled as a gradient otherwise as pixelated blocks.
DIB : By default, the function returns a DIB. Pass false if you need DDB (recommended).



The function - along with demo code

Code: Select all

CreateDIB(PixelData, W, H, ResizeW:=0, ResizeH:=0, Gradient:=0, DIB:=1) {      
Static OSV    ; CreateDIB v0.90, by SKAN on CT41/D345 @ tiny.cc/createdib 
Local  
  If ! VarSetCapacity(OSV) 
       {
         FileGetVersion, OSV, user32.dll
         OSV := Format("{1:}.{2:}", StrSplit(OSV,".")*)
       }
  LR_1   :=  0x2000|0x8|0x4              ; LR_CREATEDIBSECTION | LR_COPYDELETEORG | LR_COPYRETURNORG
  LR_2   :=         0x8|0x4                                    ; LR_COPYDELETEORG | LR_COPYRETURNORG   
  Flags  :=  ( OSV>6.3 ? (Gradient ? LR_2 : LR_1) : (Gradient ? LR_1 : LR_2) )
  WB     :=  Ceil((W*3)/2)*2,    VarSetCapacity(BMBITS, WB*H, 0),      P := &BMBITS,  PE := P+(WB*H) 

  Loop, Parse, PixelData, |
    P := P<PE ? Numput("0x" . A_LoopField, P+0, "UInt")-(W & 1 && Mod(A_Index*3, W*3)=0 ? 0 : 1) : P

  hBM := DllCall("CreateBitmap", "Int",W, "Int",H, "UInt",1, "UInt",24, "Ptr",0, "Ptr")
  hBM := DllCall("CopyImage", "Ptr",hBM, "UInt",0, "Int",0, "Int",0, "UInt",LR_1, "Ptr")
         DllCall("SetBitmapBits", "Ptr",hBM, "UInt",WB*H, "Ptr",&BMBITS)
  hBM := DllCall("CopyImage", "Ptr",hBM, "Int",0, "Int",0, "Int",0, "Int",Flags, "Ptr")
  hBM := DllCall("CopyImage", "Ptr",hBM, "Int",0, "Int",ResizeW, "Int",ResizeH, "UInt",Flags, "Ptr")
  hBM := DllCall("CopyImage", "Ptr",hBM, "Int",0, "Int",0, "Int",0, "UInt",LR_2, "Ptr")
Return DllCall("CopyImage", "Ptr",hBM, "Int",0, "Int",0, "Int",0, "UInt",DIB ? LR_1 : LR_2, "Ptr")
}    

;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 



; Usage Example follows



#NoEnv
#SingleInstance, Force
#Warn
SetBatchLines -1

PixelData_1 := "
( LTrim Join|
  FFFFFF|000000|FFFFFF|000000|FFFFFF|000000|FFFFFF|000000
  000000|FFFFFF|000000|FFFFFF|000000|FFFFFF|000000|FFFFFF
  FFFFFF|000000|FFFFFF|000000|FFFFFF|000000|FFFFFF|000000  
  000000|FFFFFF|000000|FFFFFF|000000|FFFFFF|000000|FFFFFF
  FFFFFF|000000|FFFFFF|000000|FFFFFF|000000|FFFFFF|000000  
  000000|FFFFFF|000000|FFFFFF|000000|FFFFFF|000000|FFFFFF
  FFFFFF|000000|FFFFFF|000000|FFFFFF|000000|FFFFFF|000000  
  000000|FFFFFF|000000|FFFFFF|000000|FFFFFF|000000|FFFFFF
)"
                   
PixelData_2 := "
( LTrim Join|
  CC0000|CC0000|CC0000|CC0000|CC0000|CC0000|CC0000|CC0000|CC0000
  AA0000|AA0000|AA0000|AA0000|AA0000|AA0000|AA0000|AA0000|AA0000
  990000|990000|990000|990000|990000|990000|990000|990000|990000
  880000|880000|880000|880000|880000|880000|880000|880000|880000
  770000|770000|770000|770000|770000|770000|770000|770000|770000
  660000|660000|660000|660000|660000|660000|660000|660000|660000
  550000|550000|550000|550000|550000|550000|550000|550000|550000
  440000|440000|440000|440000|440000|440000|440000|440000|440000
  330000|330000|330000|330000|330000|330000|330000|330000|330000
)"


PixelData_3 := "FF0000|00FF00|0000FF|0000FF|FF0000|00FF00"
  
Gui, 1:Margin, 0, 0
Gui, 1:Add, Picture,, % "HBITMAP:" . CreateDIB(PixelData_1, 8,8, 200,200, 0,0)
Gui, 1:Show, x100 y100, Eg.1

Gui, 2:Margin, 0, 0
Gui, 2:Add, Picture,, % "HBITMAP:" . CreateDIB(PixelData_2, 9,9, 200,200, 1,0)
Gui, 2:Show, x320 y100, Eg.2

Gui, 3:Margin, 0, 0
Gui, 3:Add, Picture,, % "HBITMAP:" . CreateDIB(PixelData_3, 3,2, 200,200, 1,0)
Gui, 3:Show, x550 y100, Eg.3
Return

GuiClose:
2GuiClose:
3GuiClose:
  ExitApp
  • Screen shot of demo :
    Attn Windows 8 users: I have tested the demo only in Windows 7 and Windows 10. Please report if there is a problem.

    Image
User avatar
TheDewd
Posts: 1391
Joined: 19 Dec 2013, 11:16
Location: USA

Re: CreateDIB()

01 Apr 2014, 08:51

Here's my creation :-)

Code: Select all

PixelData=
( LTrim Join|
  FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|000000|000000|000000|000000|000000|000000|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF
  FFFFFF|FFFFFF|FFFFFF|000000|000000|FFFFFF|FFFFFF|FF0000|FF0000|FF0000|FF0000|000000|000000|FFFFFF|FFFFFF|FFFFFF
  FFFFFF|FFFFFF|000000|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FF0000|FF0000|FF0000|FF0000|FFFFFF|FFFFFF|000000|FFFFFF|FFFFFF
  FFFFFF|000000|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FF0000|FF0000|FF0000|FF0000|FF0000|FF0000|FFFFFF|FFFFFF|000000|FFFFFF
  FFFFFF|000000|FFFFFF|FFFFFF|FFFFFF|FF0000|FF0000|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FF0000|FF0000|FFFFFF|000000|FFFFFF
  000000|FF0000|FF0000|FF0000|FF0000|FF0000|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FF0000|FF0000|FF0000|000000
  000000|FF0000|FFFFFF|FFFFFF|FF0000|FF0000|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FF0000|FF0000|FF0000|000000
  000000|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FF0000|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FF0000|FF0000|FFFFFF|000000
  000000|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FF0000|FF0000|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FF0000|FF0000|FFFFFF|FFFFFF|000000
  000000|FF0000|FFFFFF|FFFFFF|FF0000|FF0000|FF0000|FF0000|FF0000|FF0000|FF0000|FF0000|FF0000|FFFFFF|FFFFFF|000000
  000000|FF0000|FF0000|FF0000|000000|000000|000000|000000|000000|000000|000000|000000|FF0000|FF0000|FFFFFF|000000
  FFFFFF|000000|000000|000000|FFFFFF|FFFFFF|000000|FFFFFF|FFFFFF|000000|FFFFFF|FFFFFF|000000|000000|000000|FFFFFF
  FFFFFF|FFFFFF|000000|FFFFFF|FFFFFF|FFFFFF|000000|FFFFFF|FFFFFF|000000|FFFFFF|FFFFFF|FFFFFF|000000|FFFFFF|FFFFFF
  FFFFFF|FFFFFF|000000|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|000000|FFFFFF|FFFFFF
  FFFFFF|FFFFFF|FFFFFF|000000|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|000000|FFFFFF|FFFFFF|FFFFFF
  FFFFFF|FFFFFF|FFFFFF|FFFFFF|000000|000000|000000|000000|000000|000000|000000|000000|FFFFFF|FFFFFF|FFFFFF|FFFFFF
)
hBM := CreateDIB( PixelData, 16, 16 )
Image Bulldozer - Sokoban inspired game from 1994 recreated in AutoHotkey.
tmplinshi
Posts: 1560
Joined: 01 Oct 2013, 14:57

Re: CreateDIB()

02 Apr 2014, 00:15

Last edited by tmplinshi on 02 Apr 2014, 06:37, edited 5 times in total.
just me
Posts: 7112
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: CreateDIB()

02 Apr 2014, 01:05

Hi SKAN,

Code: Select all

P := Numput( "0x" A_LoopField, P+0 ) - ( W & 1 && !Mod( A_Index * 3, W * 3 ) ? 0 : 1 )
NumPut(Number, VarOrAddress [, Offset = 0][, Type = "UPtr"])
It does not run with AHK x64.
tmplinshi
Posts: 1560
Joined: 01 Oct 2013, 14:57

Re: CreateDIB()

02 Apr 2014, 05:49

Here is small tool to convert image to PixelData.

Image

:arrow: Download: https://drive.google.com/open?id=1YBmvX ... Ygl_4di0IJ
Last edited by tmplinshi on 02 Aug 2018, 01:23, edited 2 times in total.
User avatar
SKAN
Posts: 612
Joined: 29 Sep 2013, 16:58

Re: CreateDIB()

04 Apr 2014, 16:28

just me wrote:NumPut(Number, VarOrAddress [, Offset = 0][, Type = "UPtr"])
So, I have to specify "UInt" as last parameter!. Okay.
I will test and post AHK 1.1 specific code in a few days.
User avatar
SKAN
Posts: 612
Joined: 29 Sep 2013, 16:58

Re: CreateDIB()

04 Apr 2014, 17:14

CreateDIB() can also produce gradient bitmaps.

  • A screenshot of "pseudo-skinned" GUI that uses CreateDIB()

    Image
Basic 1px bitmaps :

Code: Select all

hBM_Black := CreateDIB( "101010", 1, 1 )
hBM_Gray  := CreateDIB( "606060", 1, 1 )
hBM_White := CreateDIB( "CCCCCC", 1, 1 )
; * The polygon behind close button is actually 18 x "h1" bitmaps of hBM_Gray


Titlebar gradient:

Code: Select all

hBM_Title := CreateDIB( "606060|606060|101010|101010", 2, 2, 220, 18  )
Horizontal line gradient:

Code: Select all

hBM_Horz  := CreateDIB( "0|0|0|606060|808080|606060|0|0|0", 3, 3, 220, 3  )
10x10 Close button:

Code: Select all

PixelData :=  "---$$$$----XX-$$-XX--XXX--XXX-$-XXXXXX-$$$-XXXX-$$"
          .   "$$-XXXX-$$$-XXXXXX-$-XXX--XXX--XX-$$-XX----$$$$---"
StringReplace, PixelData, PixelData, -, 101010|, All
StringReplace, PixelData, PixelData, X, CCCCCC|, All
StringReplace, PixelData, PixelData, $, 606060|, All
StringTrimRight, PixelData, PixelData, 1

hBM_Close := CreateDIB( PixelData, 10, 10 )
Connect/Hangup buttons background gradient.

Code: Select all

hBM_BBG := CreateDIB( "808080|DDDDDD|808080", 3, 1, 58, 18  )
; The black border surrounding buttons is 60x20 hBM_Black placed behind.
tmplinshi
Posts: 1560
Joined: 01 Oct 2013, 14:57

Re: CreateDIB()

04 Apr 2014, 21:43

SKAN wrote:CreateDIB() can also produce gradient bitmaps.
Very nice! 8-) Didn't thought about this usage.
User avatar
xZomBie
Posts: 256
Joined: 02 Oct 2013, 02:57

Re: CreateDIB()

05 Apr 2014, 00:16

SKAN wrote:
just me wrote:NumPut(Number, VarOrAddress [, Offset = 0][, Type = "UPtr"])
So, I have to specify "UInt" as last parameter!. Okay.
I will test and post AHK 1.1 specific code in a few days.
When will there be a fix for AHK x64? Extremely EXCITED to play with this!!
User avatar
SKAN
Posts: 612
Joined: 29 Sep 2013, 16:58

Re: CreateDIB()

05 May 2014, 03:26

xZomBie wrote:fix for AHK x64?
Fixed, hopefully. Title post updated.
User avatar
xZomBie
Posts: 256
Joined: 02 Oct 2013, 02:57

Re: CreateDIB()

05 May 2014, 06:17

Yeah! Tested and working! Thanks SKAN!!
User avatar
xZomBie
Posts: 256
Joined: 02 Oct 2013, 02:57

Re: CreateDIB()

09 May 2014, 03:08

ME!

Code: Select all

#NoEnv
#SingleInstance, Force
SetBatchLines -1

PixelData=
( LTrim Join|
	FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFF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A5|FFFFFF|FFFFFF|DCDCDC|949494|949494|A5A5A5|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF
	FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|DCDCDC|787878|000000|000000|1C1C1C|A5A5A5|DCDCDC|787878|000000|000000|1C1C1C|A5A5A5|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF
	FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|D1D1D1|595959|484848|000000|000000|1C1C1C|787878|000000|000000|111111|595959|757575|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF
	FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|DCDCDC|949494|949494|949494|787878|000000|000000|000000|000000|000000|000000|1C1C1C|949494|A5A5A5|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF
	FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|D1D1D1|484848|000000|000000|000000|000000|000000|000000|000000|000000|000000|000000|000000|1C1C1C|949494|949494|A5A5A5|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF
	FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|D1D1D1|484848|000000|000000|000000|000000|000000|000000|000000|000000|000000|000000|000000|000000|111111|757575|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF
	FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|C0C0C0|000000|000000|000000|000000|000000|000000|000000|000000|000000|000000|000000|111111|757575|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF
	FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|DCDCDC|787878|000000|000000|000000|000000|050A05|1D351C|1D351C|1D351C|182B16|000000|000000|1C1C1C|949494|A5A5A5|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF
	FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|DCDCDC|7D827D|1D351C|1D351C|182B16|000000|050A05|264624|4F8F4B|4F8F4B|4F8F4B|40743C|050A05|182B16|000000|111111|757575|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF
	FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|D1D1D1|515850|31592E|366334|457E42|1D351C|264624|498445|31592E|366334|4F8F4B|457E42|264624|40743C|111111|757575|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF
	FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|DCDCDC|828980|3A5F2B|385E2B|366334|4F8F4B|498445|335A2E|3A5F2B|385E2B|366334|4F8F4B|4F8F4B|40743C|2D2D2D|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF
	FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|C0C0C0|1D2F15|9BFF73|7DCF5D|0E1A0E|4F8F4B|40743C|1D2F15|9BFF73|7DCF5D|0E1A0E|4F8F4B|4F8F4B|40743C|2D2D2D|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF
	FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|D1D1D1|5A6555|609F47|4E813A|0E1A0E|4F8F4B|40743C|121D0D|609F47|548B3F|264624|498445|31592E|395937|757575|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF
	FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|D1D1D1|484848|050A05|264624|4F8F4B|457E42|1D351C|1D351C|264624|4F8F4B|40743C|111111|757575|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF
	FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|D1D1D1|515850|3C6B36|60A751|3C6B36|60A751|3C6B36|66B157|498445|2D522B|344732|949494|949494|A5A5A5|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF
	FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|D1D1D1|5A6555|599342|416B30|4E813A|121D0D|5D9C48|40743C|091008|2D522B|182B16|0A1108|4B693F|A5A5A5|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF
	FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|D1D1D1|5A6555|4E813A|0A1108|2F4D23|142210|579649|000000|091008|284826|121D0D|4E813A|1C1C1C|949494|A5A5A5|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF
	FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|D1D1D1|595959|5A6555|4E813A|121D0D|4E813A|0A1108|3A5F2B|3A5F2B|2F4D23|050A05|1D351C|1D351C|344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|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF
	FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|DCDCDC|7D827D|264624|4F8F4B|4F8F4B|498445|31592E|31592E|31592E|31592E|3A6633|4E813A|2D2D2D|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF
	FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|DCDCDC|828980|385E2B|3C6B36|60A751|31592E|284826|050A05|182B16|000000|000000|000000|000000|2D2D2D|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF
	FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|C0C0C0|121D0D|5F924B|5A6555|4E813A|111111|484848|142210|579649|000000|000000|000000|000000|2D2D2D|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF
	FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|D1D1D1|595959|757575|D1D1D1|595959|757575|C0C0C0|1D2F15|7DCF5D|000000|000000|000000|0A1108|4B693F|A5A5A5|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF
	F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FF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF
	
)
hBM := CreateDIB( PixelData, 39, 39 )

Gui, Margin, 0, 0
Gui, Add, Picture, w198 h198 0x4E hwndcHwnd ; SS_REALSIZECONTROL = 0x40 | SS_BITMAP = 0xE
DllCall( "SendMessage", UInt,cHwnd, UInt,0x172, UInt,0, UInt,hBM ) ; STM_SETIMAGE = 0x172
Gui, Show

Return

GuiClose:
ExitApp

CreateDIB( PixelData, W, H, ResizeW := 0, ResizeH := 0, Gradient := 1  ) {
; http://ahkscript.org/boards/viewtopic.php?t=3203                  SKAN, CD: 01-Apr-2014 MD: 05-May-2014
Static LR_Flag1 := 0x2008 ; LR_CREATEDIBSECTION := 0x2000 | LR_COPYDELETEORG := 8
    ,  LR_Flag2 := 0x200C ; LR_CREATEDIBSECTION := 0x2000 | LR_COPYDELETEORG := 8 | LR_COPYRETURNORG := 4
    ,  LR_Flag3 := 0x0008 ; LR_COPYDELETEORG := 8

  WB := Ceil( ( W * 3 ) / 2 ) * 2,  VarSetCapacity( BMBITS, WB * H + 1, 0 ),  P := &BMBITS
  Loop, Parse, PixelData, |
    P := Numput( "0x" A_LoopField, P+0, 0, "UInt" ) - ( W & 1 and Mod( A_Index * 3, W * 3 ) = 0 ? 0 : 1 )

  hBM := DllCall( "CreateBitmap", "Int",W, "Int",H, "UInt",1, "UInt",24, "Ptr",0, "Ptr" )
  hBM := DllCall( "CopyImage", "Ptr",hBM, "UInt",0, "Int",0, "Int",0, "UInt",LR_Flag1, "Ptr" )
  DllCall( "SetBitmapBits", "Ptr",hBM, "UInt",WB * H, "Ptr",&BMBITS )

  If not ( Gradient + 0 )
     hBM := DllCall( "CopyImage", "Ptr",hBM, "UInt",0, "Int",0, "Int",0, "UInt",LR_Flag3, "Ptr" )
Return DllCall( "CopyImage", "Ptr",hBM, "Int",0, "Int",ResizeW, "Int",ResizeH, "Int",LR_Flag2, "UPtr" )
}
User avatar
jNizM
Posts: 2613
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: CreateDIB()

21 May 2014, 01:15

@tmplinshi
your tool do not work correct with eg 250x76px
(how can i save the image? convert without pixel dont work. with 250x76 i got only 1 colored pixel)

or @SKAN
can CreateDIB() only be used for quadratic images or for rectangle images too?

Image
[AHK] 1.1.32.00 x64 Unicode | [WIN] 10 Pro (Version 2004) x64 | [GitHub] Profile
Donations are appreciated if I could help you
User avatar
SKAN
Posts: 612
Joined: 29 Sep 2013, 16:58

Re: CreateDIB()

21 May 2014, 21:28

jNizM, bitmaps are rectangular.
The only requirement: The number of elements passed as PixelData should equal Width x Height.
tmplinshi
Posts: 1560
Joined: 01 Oct 2013, 14:57

Re: CreateDIB()

22 May 2014, 00:08

@jNizM
Sorry, the width and height in "PixelData Creator" are not the image size, but stands for every color size, see this image.
User avatar
jNizM
Posts: 2613
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: CreateDIB()

22 May 2014, 00:40

@tmplinshi
can you rewrite you tool to export the whole image, not only 1px
and more flexible for different sizes eg. 20x20px, 80x60px or 40x120px
[AHK] 1.1.32.00 x64 Unicode | [WIN] 10 Pro (Version 2004) x64 | [GitHub] Profile
Donations are appreciated if I could help you
tmplinshi
Posts: 1560
Joined: 01 Oct 2013, 14:57

Re: CreateDIB()

22 May 2014, 01:05

I don't quite understand what you mean. You can type different width and height in the GUI. Or would you please provide a sample image?
User avatar
jNizM
Posts: 2613
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: CreateDIB()

22 May 2014, 01:17

- More flexible:
My test.img (https://dl.dropboxusercontent.com/u/186 ... t_Logo.png) is 499 x 285 px
If I import this in your tool its resized too quadratic [H EQUAL W] (see some post above)

- export:
atm i can only export 1 px..
can you rewrite it to export the whole image with the CreateDIB() function
[AHK] 1.1.32.00 x64 Unicode | [WIN] 10 Pro (Version 2004) x64 | [GitHub] Profile
Donations are appreciated if I could help you
tmplinshi
Posts: 1560
Joined: 01 Oct 2013, 14:57

Re: CreateDIB()

22 May 2014, 01:50

oh, that's just a preview in the GUI, not the output size.

Try 8x8:
Image
User avatar
SKAN
Posts: 612
Joined: 29 Sep 2013, 16:58

Re: CreateDIB() : Create hBitmap with series of RRGGBB hex values.

04 Apr 2020, 19:06

Topic/code updated

CreateDIB() v0.90
Rewrote the function to work in Windows 10
I would be glad in any Windows 8 user can test and let me know if the demo code is working properly.

Return to “Scripts and Functions”

Who is online

Users browsing this forum: No registered users and 133 guests