[Class] LoadPictureType

Post your working scripts, libraries and tools
Helgef
Posts: 1635
Joined: 17 Jul 2016, 01:02

[Class] LoadPictureType

16 Jun 2017, 09:41

Introduction

This is for loading a picture and specifying the type of the returned handle, that is, hBitmap, hIcon or hCursor.

Usage

Code: [Select all] [Download] GeSHi © Codebox Plus

ref := new LoadPictureType(Filename [, options:="", ImageType:=0, bkColor:=0x000000, xHotspot:=0, yHotspot:=0,keepBITMAP:=false])

For Filename and options, use the regular LoadPicture parameters.
The parameter ImageType specifies the type of the returned handle, set it to either IMAGE_BITMAP:=0, IMAGE_ICON:=1 or IMAGE_CURSOR:=2
Most basic example:

Code: [Select all] [Download] GeSHi © Codebox Plus

icon:= new LoadPictureType("myBitmap.bmp" ,"w55 h100", IMAGE_ICON:=1)
myIconHandle:=icon.getHandle()

If getting an icon or cursor handle, specify the background color (RGB) of the bitmap, via the bkColor parameter, this color will be transparent.
For cursors, you may specify the hotspot coordinates, via the xHotspot and yHotspot parameters.
You can set the keepBITMAP parameter to true if you want to call the ref.getBitmap() method, to obtain the info of a BITMAP structure as an ahk array on the form:

Code: [Select all] [Download] GeSHi © Codebox Plus

BITMAP	:=	{type:			bmType
,w: bmWidth
,h: bmHeight
,widthBytes: bmWidthBytes
,planes: bmPlanes
,bitsPixel: bmBitsPixel
,bits: bmBits}

This feature is a concequnce of debugging.

Known limitations

  • Sometimes fails if the gdi+ option is present.
  • Transparency fails on some non-bitmap images.
  • This has almost zero value if you want a bitmap handle, then just use LoadPicture.
  • Limited testing

Misc.

I know very little about gdi, I'm sure there is a better way to do this, please tell me.
For reference: I have used the logic found here.
As far a I am concerned, you may use this code in any peaceful context you wish, but remember the above reference. The provided bitmap below is not for sale, it is owned by its author, a professional graphics artist :rainbow: .
:arrow: github

Download

LoadPictureType.ahk
(11.42 KiB) Downloaded 4 times

Example:
Change the Windows cursor, restored on exit (Esc).
Save image as myBmp.bmp and put in script directory.
example.ahk
(1.19 KiB) Downloaded 6 times

Image


Cheers.

Return to “Scripts and Functions”

Who is online

Users browsing this forum: Flipeador, sttrebo and 16 guests