CreateDIB()

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

CreateDIB()

01 Apr 2014, 08:29

Note: To avoid buffer overrun, the number of elements passed as PixelData should not exceed Width x Height

AutoHotkey 1.1

Code: Select all

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" )
}    
   


; Usage Example follows

#SingleInstance, Force

PixelData=
( 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
)                   
hBM := CreateDIB( PixelData, 8, 8 )

Gui, Margin, 0, 0
Gui, Add, Picture, w640 h640 0x4E hwndcHwnd ; SS_REALSIZECONTROL = 0x40 | SS_BITMAP = 0xE
DllCall( "SendMessage", "Ptr",cHwnd, "UInt",0x172, "Ptr",0, "Ptr",hBM ) ; STM_SETIMAGE = 0x172
Gui, Show,, CreateDIB() Demo

Generic 32bit code. Works in AutoHotkey Classic.

Code: Select all

CreateDIB( PixelData, W, H, ResizeW=0, ResizeH=0, Gradient=1  ) { ;     SKAN, 01-Apr-2014
  WB := Ceil( ( W * 3 )/ 2 ) * 2,  VarSetCapacity( BMBITS, WB * H + 1, 0 ),  P := &BMBITS
  Loop, Parse, PixelData, |
   P := Numput( "0x" A_LoopField, P+0 ) - ( W & 1 && !Mod( A_Index * 3, W * 3 ) ? 0 : 1 )
  hBM := DllCall( "CreateBitmap", Int,W, Int,H, UInt,1, UInt,24, UInt,0 )    
  hBM := DllCall( "CopyImage", UInt,hBM, Int,0, Int,0, Int,0, UInt,0x2008 ) 
  DllCall( "SetBitmapBits", UInt,hBM, UInt,WB * H, UInt,&BMBITS )
  hBM := ! Gradient ? DllCall( "CopyImage", UInt,hBM, UInt,0, Int,0, Int,0, Int,8 ) : hBM 
Return DllCall( "CopyImage", UInt,hBM, Int,0, Int,ResizeW, Int,ResizeH, Int,0x200C, UInt )
} ; http://ahkscript.org/boards/viewtopic.php?t=3203   


; Usage Example follows

#SingleInstance, Force

PixelData=
( 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
)                   
hBM := CreateDIB( PixelData, 8, 8 )

Gui, Margin, 0, 0
Gui, Add, Picture, w640 h640 0x4E hwndcHwnd ; SS_REALSIZECONTROL = 0x40 | SS_BITMAP = 0xE
DllCall( "SendMessage", UInt,cHwnd, UInt,0x172, UInt,0, UInt,hBM ) ; STM_SETIMAGE = 0x172
Gui, Show,, CreateDIB() Demo
  • Image
User avatar
TheDewd
Posts: 1390
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: 1557
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: 6793
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: 1557
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: 406
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: 406
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: 1557
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: 406
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|F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FFFFFF|FFFFFF|FFFFFF
	FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|DCDCDC|949494|949494|A5A5A5|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|FFF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FFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|DCDCDC|7D827D|1D351C|1D351C|1D351C|1D351C|1D351C|1D351C|1D351C|2C4E27|579649|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|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
	FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|FFFFFF|DCDCDC|787878|121D0D|4E813A|000000|000000|0A1108|4C7D38|7DCF5D|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|949494|949494|949494|828980|2F4D23|000000|000000|0A1108|3A5F2B|4C7D38|90ED6A|548B3F|344732|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|C0C0C0|050A05|1D351C|182B16|1D2F15|88E165|3A5F2B|3A5F2B|4C7D38|9BFF73|90ED6A|548B3F|264624|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|0E1A0E|4F8F4B|457E42|2A4924|6BB14F|9BFF73|9BFF73|9BFF73|90ED6A|548B3F|264624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FFFFF|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|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: 2583
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.30.03 x64 Unicode | [WIN] 10 Pro (Version 1909) x64 | [GitHub] Profile
Donations are appreciated if I could help you
User avatar
SKAN
Posts: 406
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: 1557
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: 2583
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.30.03 x64 Unicode | [WIN] 10 Pro (Version 1909) x64 | [GitHub] Profile
Donations are appreciated if I could help you
tmplinshi
Posts: 1557
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: 2583
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.30.03 x64 Unicode | [WIN] 10 Pro (Version 1909) x64 | [GitHub] Profile
Donations are appreciated if I could help you
tmplinshi
Posts: 1557
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

Return to “Scripts and Functions”

Who is online

Users browsing this forum: robodesign and 110 guests