ImagePut - A core library for images in AutoHotkey (Now supports HEIC & WEBP)

Post your working scripts, libraries and tools for AHK v1.1 and older
iseahound
Posts: 1427
Joined: 13 Aug 2016, 21:04
Contact:

ImagePut - A core library for images in AutoHotkey (Now supports HEIC & WEBP)

Post by iseahound » 22 May 2020, 15:05

ImagePut
A core library for images in AutoHotkey

image.png
image.png (76.28 KiB) Viewed 487 times

Imagine a scenario where you have a file but you're trying to get it uploaded into an API. Or you have a function that returns some strange image format, is there any way you can *just* get it to show its contents? If you pass anything, literally anything you believe is an image to ImagePutWindow() it will show up on screen. And then you can magically transform it to be compatible with that specific API.

Features
  • Simple and effective
  • Decipher over 20+ image types
  • Supports newer formats webp and heic
  • View and debug your image functions with ImagePutWindow(image)
  • Screen capture with fast PixelSearch and ImageSearch
  • Add animated GIFs to AutoHotkey GUIs
  • Upload images using website apis
  • Load images from blocks of memory

Beginner

Intermediate

Documentation
Tutorials Misc
Advanced
So you want to convert an image?
But you don't know how. That's okay because you can just do this:

Code: Select all

str := ImagePutBase64("cats.jpg")
or this

Code: Select all

ImagePutClipboard("https://example.com/cats.jpg")
or something like this:

Code: Select all

pStream := ImagePutStream([0, 0, A_ScreenWidth, A_ScreenHeight])
Working with images should be this easy. ImagePut has automatic type inference, meaning that it will guess whether the input is (1) a file (2) a website url or (3) a series of coordinates that map to the screen. This functionality enables the user to only memorize a single function for any possible input. For a full list of supported input types, click on the documentation link here. For output types click here.

Convert file formats.

Code: Select all

; Saves a JPEG as a GIF.
ImagePutFile("cats.jpg", "gif")
Convert file formats and image types at the same time!

Code: Select all

; Saves a JPEG as a base64 encoded GIF.
str := ImagePutBase64("cats.jpg", "gif")
There's also some weird functions like ImagePutCursor which lets you set anything as your cursor. Make sure you don't choose an extremely large image!

Finally, there are several advanced features. The first is the ability to specify the input type directly. The second is cropping and scaling functionality. Third is use of ImageEqual() a function that can compare multiple inputs across different windows image data types!

Code: Select all

; Declare input type as file.
ImagePutWindow({file: "cats.jpg"})

; Scale 2x and crop 10% from each edge.
ImagePutWindow({file: "cats.jpg", scale: 2, crop:["-10%", "-10%", "-10%", "-10%"]})

; Unknown image type declared as "image" to be cropped to 200x200 pixels.
ImagePutWindow({image: "cats.jpg", crop: [0, 0, 200, 200]})

; Compare a url to a file.
MsgBox % ImageEqual("https://example.com/cats.jpg", "cats.jpg")

; Validate an image as an actual image.
ImageEqual("cats.jpg")

Design Philosophy
  • 100% Compatibility with Gdip_All.ahk
  • ImagePut is designed to be the fastest
  • ImagePut should serve as a reference implementation
  • Specific conversions between formats like PNG file to hIcon are not considered
  • Users should be able to replace uses of ImagePut with individual functions
  • Therefore users should be copy and paste individual functions
  • If you need help extracting a function please ask!

Help and Support

Feel free to ask for any help, questions, or post suggestions, etc.
Download
Last edited by iseahound on 05 Feb 2024, 15:37, edited 45 times in total.

iseahound
Posts: 1427
Joined: 13 Aug 2016, 21:04
Contact:

Re: ImagePut - Puts an image from anywhere to anywhere

Post by iseahound » 22 May 2020, 15:12

Sometimes I change my cursor to Taylor Swift and turn on mouse trails.

Code: Select all

ImagePutCursor("https://i.imgur.com/F4k7o1e.png",, 50)

robodesign
Posts: 932
Joined: 30 Sep 2017, 03:59
Location: Romania
Contact:

Re: ImagePut - Puts an image from anywhere to anywhere

Post by robodesign » 22 May 2020, 17:13

Impressive work, I'd say, just by reading the well written code.
-------------------------
KeyPress OSD v4: GitHub or forum. (presentation video)
Quick Picto Viewer: GitHub or forum.
AHK GDI+ expanded / compilation library (on GitHub)
My home page.

iseahound
Posts: 1427
Joined: 13 Aug 2016, 21:04
Contact:

Re: ImagePut - Puts an image from anywhere to anywhere

Post by iseahound » 22 May 2020, 19:51

Quick note for anyone who already downloaded this class: I've added an error message to ImagePutBitmap(image) letting users know that their pointer is out of scope. ImagePut loads and unloads GDI+ (transparently) with each call unless the user loads it manually.

iseahound
Posts: 1427
Joined: 13 Aug 2016, 21:04
Contact:

Re: ImagePut - Puts an image from anywhere to anywhere (convert, crop, scale)

Post by iseahound » 29 Jul 2020, 19:50

There's major updates on Github! The specific changes can be found on the v2 forum here:
https://www.autohotkey.com/boards/viewtopic.php?f=83&t=76633&p=332297

From now on, major developments will happen on the v2 branch and be backported to v1. Writing code is just so much smoother on v2, and several built in functions are just better. As a short summary, Clipboard and Monitor functions have been added to v2 and backported to v1. The clipboard functions are less robust in v1 but still support transferring a PNG stream instead of an hBitmap like tic's Gdip code did. The monitor types only exist on v2 with the exception of sending the number 0 to mean the entire virtual screen.

iseahound
Posts: 1427
Joined: 13 Aug 2016, 21:04
Contact:

Re: ImagePut - Windows Image Transformation Library

Post by iseahound » 07 Sep 2020, 21:21

Fixed monitor numbers as an input type, so that ImagePutFile(1) now properly copies the first monitor, ImagePutFile(2) the second, and so on...

User avatar
SpeedMaster
Posts: 494
Joined: 12 Nov 2016, 16:09

Re: ImagePut - Windows Image Transformation Library

Post by SpeedMaster » 24 Oct 2020, 15:14

iseahound wrote:
22 May 2020, 15:12
Sometimes I change my cursor to Taylor Swift and turn on mouse trails.
8-) :lol: she inspired me...
Press Win + F1 to toggle a big cursor

Code: Select all

; Script name: Toggle Big Cursor
; Shortcut:  press Win + F1 to toggle big cursor

#SingleInstance force

#include imageput.ahk

onexit,exit

if !FileExist("big_yellow_cursor.png")
gosub createcursor


#f1::
toggle:=!toggle
if toggle
ImagePutCursor("big_yellow_cursor.png","0",0)
else
DllCall("SystemParametersInfo", "uint", 0x57, "uint", 0, "ptr", 0, "uint", 0)
return


exit:
DllCall("SystemParametersInfo", "uint", 0x57, "uint", 0, "ptr", 0, "uint", 0)
esc::exitapp
return

createcursor:
Base64ImageData=
(
 iVBORw0KGgoAAAANSUhEUgAAADAAAABICAYAAACwc3YrAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAOwgAADsIBFShKgAAAABp0RVh0U29mdHdhcmUAUGFpbnQuTkVUIHYzLjUuMTFH80I3AAAFDUlEQVRoQ9WaSUwsVRSGmR8qgTDIJAlBEBY47Ygx0RBxwRAWroAgIbJgo8HniKjIDhMWJmwxYYYFY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7HXg9cbeI+YceAWuA84iZ04KBDoXe78V6AVyHSD74A/bm5u7tIckqqqKjnfO6AMxI6dVAqMjIwE2+ZjIHfehO9H3gX+WH7KIIuWTE1NecXFxWbOb8C9IHbMhFaAPz2TjwPuvFa8yePAjuf3ZcHiDTU1NWYcN+UZEDt24dXVVX/nxWNhbaPlc+BfNzAwoBZP+vv75fyfgCoQK3bCtrY2rW0eBJnkOfAn8HtdK56sra15paWlZo2fwBCIFTNZEO58psUzXeAG8K+fnZ1VBUh3d7dcZwPEipyMcOe/Bpm0TTB8ZfHnaW9vV4snCwsLcr0/QJS1bORkLJ59mc3OyzwCfgZ+K66srKgChGME/KKjBESKnIg7/xCImhrwHvDn6+3tva3wpaUlr7OzU65JPgNNIFI4gWmbe/hAzDwFbHGmcP7lVl1dbR8X8CfO2yByG7H4T0GcnZfhrxnt/8w9PT1eV1eXfOUx/AgOwZPgLhA5cdtGy9uAGxMsmvwFPgRPAPWTtmzjom2CeRh8D2ThfBu9Bx4Fzt6J5irl4ACwcLbKEYjdKklnELwPBoCTVrk9RUX/AmsYEU5HH6ykAAAAAElFTkSuQmCC
)


nBytes := Base64Dec( Base64ImageData, Bin )

File := FileOpen("big_yellow_cursor.png", "w")
File.RawWrite(Bin, nBytes)
File.Close()

Return ;    // end of auto-execcute section //

Base64Dec( ByRef B64, ByRef Bin ) {  ; By SKAN / 18-Aug-2017
Local Rqd := 0, BLen := StrLen(B64)                 ; CRYPT_STRING_BASE64 := 0x1
  DllCall( "Crypt32.dll\CryptStringToBinary", "Str",B64, "UInt",BLen, "UInt",0x1
         , "UInt",0, "UIntP",Rqd, "Int",0, "Int",0 )
  VarSetCapacity( Bin, 128 ), VarSetCapacity( Bin, 0 ),  VarSetCapacity( Bin, Rqd, 0 )
  DllCall( "Crypt32.dll\CryptStringToBinary", "Str",B64, "UInt",BLen, "UInt",0x1
         , "Ptr",&Bin, "UIntP",Rqd, "Int",0, "Int",0 )
Return Rqd
}


iseahound
Posts: 1427
Joined: 13 Aug 2016, 21:04
Contact:

Re: ImagePut - Windows Image Transformation Library

Post by iseahound » 27 Oct 2020, 11:49

You can actually use the base64 data directly.

Code: Select all

ImagePutCursor("iVBORw0KGgoAAAANSUhEUgAAADAAAABICAYAAACwc3YrAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAOwgAADsIBFShKgAAAABp0RVh0U29mdHdhcmUAUGFpbnQuTkVUIHYzLjUuMTFH80I3AAAFDUlEQVRoQ9WaSUwsVRSGmR8qgTDIJAlBEBY47Ygx0RBxwRAWroAgIbJgo8HniKjIDhMWJmwxYYYFYcYYXTstnJa6eRtduDEahxf1Rcv/r+ReD/VOSXfV7erqP/mSl+5b957v3lP9mu4uQt4Cd/IfhZrfQUFLeMBIFGQoYCjIk5ACPIlFUFASUkBKFEyCAoaCOQlbdHl5uRQomHayRU9MTHgNDQ1S4jfwJkh1bMEHBweed/Oa19raKiUIJVJ7ErZQI0BCTiKVEqrA/v6+JvEGSF1UAYPSTpRI1UnY4jQBUl9fLwXMSaRG4koBtpMi8TpIRa4UMCjtRIk7QF5jC7pK4OLiIuwk8iqRsQDZ29vTJBZA3pKVAOFJtLS0SAlCibychC0iUwFyfn4edhKJS0QSILu7u5rEayDRRBYgPAmlnSiR2EnYhaMIEErU1dVJgUTbKbYA2dnZ0STmQc7jRICcnZ15zc3NUoJQIqcnYReLK0AoETiJX0FOJZwKkO3tbU3iVZCTOBcgp6enWjtRwvlJ2AVcChBKJNFOORMgW1tbmsQrwFlyKkBC2okSTk7CTporARLSTk7uiUQESEg7vQxiJTEBcnJyorUTJSKfhJ0oCQFCiZAbuxJkncQFyObmpibxEsg6eREgx8fHXlNTk5QglMjqJOzFSQsQStTW1koBc2NnLJFXAbK+vq5JZNxOeRcgR0dHXmNjo5QgL4IrT8JekE8BQoko7ZQaAaK00y/gBRCaVAmQw8NDrZ0ooZ6EHZQWAUIJ5STUeyKVAmR6etqrqKgISlwHl5ITgY6ODrmwS/4BlLAnYZ90KTAzMyMXdc2ldrJPuG6hyspKuahrKPE8+O/BKAKLi4vq42RwcFAu+C24G9Q7pA5EF2CB/HCXHy1qz29sbEiBv8FjwHkiCYyNjdnrJicn1TEk8On1GrgGnMYukKnA0NCQLMp/qdPGkfn5ea+kpMSM/QHcD5zGFpKJAIsvKyuz1xiWl5fV8UT8CcmXQOffbtoirhKQbROkr69PvYYMDw/LsV8C3oDOYif/P4FA23AnWcizgB+j+20Sdj1vcvFTnpvgaeAstrCwAriDom1Y/EfgAdAAvgD+c6Ojo+r1hCdkxoEPQDFwEjuxJjA+Pi4XJtx5Fm/Cnx34z7HXg9cbeI+YceAWuA84iZ04KBDoXe78V6AVyHSD74A/bm5u7tIckqqqKjnfO6AMxI6dVAqMjIwE2+ZjIHfehO9H3gX+WH7KIIuWTE1NecXFxWbOb8C9IHbMhFaAPz2TjwPuvFa8yePAjuf3ZcHiDTU1NWYcN+UZEDt24dXVVX/nxWNhbaPlc+BfNzAwoBZP+vv75fyfgCoQK3bCtrY2rW0eBJnkOfAn8HtdK56sra15paWlZo2fwBCIFTNZEO58psUzXeAG8K+fnZ1VBUh3d7dcZwPEipyMcOe/Bpm0TTB8ZfHnaW9vV4snCwsLcr0/QJS1bORkLJ59mc3OyzwCfgZ+K66srKgChGME/KKjBESKnIg7/xCImhrwHvDn6+3tva3wpaUlr7OzU65JPgNNIFI4gWmbe/hAzDwFbHGmcP7lVl1dbR8X8CfO2yByG7H4T0GcnZfhrxnt/8w9PT1eV1eXfOUx/AgOwZPgLhA5cdtGy9uAGxMsmvwFPgRPAPWTtmzjom2CeRh8D2ThfBu9Bx4Fzt6J5irl4ACwcLbKEYjdKklnELwPBoCTVrk9RUX/AmsYEU5HH6ykAAAAAElFTkSuQmCC", 0, 0)
You also need to set the xHotspot and yHotspot to (0, 0) as it defaults to the center of the mouse.

Code: Select all

Base64ImageData=
(
iVBORw0KGgoAAAANSUhEUgAAADAAAABICAYAAACwc3YrAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAOwgAADsI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irhKQbROkr69PvYYMDw/LsV8C3oDOYif/P4FA23AnWcizgB+j+20Sdj1vcvFTnpvgaeAstrCwAriDom1Y/EfgAdAAvgD+c6Ojo+r1hCdkxoEPQDFwEjuxJjA+Pi4XJtx5Fm/Cnx34z7HXg9cbeI+YceAWuA84iZ04KBDoXe78V6AVyHSD74A/bm5u7tIckqqqKjnfO6AMxI6dVAqMjIwE2+ZjIHfehO9H3gX+WH7KIIuWTE1NecXFxWbOb8C9IHbMhFaAPz2TjwPuvFa8yePAjuf3ZcHiDTU1NWYcN+UZEDt24dXVVX/nxWNhbaPlc+BfNzAwoBZP+vv75fyfgCoQK3bCtrY2rW0eBJnkOfAn8HtdK56sra15paWlZo2fwBCIFTNZEO58psUzXeAG8K+fnZ1VBUh3d7dcZwPEipyMcOe/Bpm0TTB8ZfHnaW9vV4snCwsLcr0/QJS1bORkLJ59mc3OyzwCfgZ+K66srKgChGME/KKjBESKnIg7/xCImhrwHvDn6+3tva3wpaUlr7OzU65JPgNNIFI4gWmbe/hAzDwFbHGmcP7lVl1dbR8X8CfO2yByG7H4T0GcnZfhrxnt/8w9PT1eV1eXfOUx/AgOwZPgLhA5cdtGy9uAGxMsmvwFPgRPAPWTtmzjom2CeRh8D2ThfBu9Bx4Fzt6J5irl4ACwcLbKEYjdKklnELwPBoCTVrk9RUX/AmsYEU5HH6ykAAAAAElFTkSuQmCC
)

ImagePutCursor(Base64ImageData, 0, 0) ; x, y hotspots
Cool usage!

User avatar
SpeedMaster
Posts: 494
Joined: 12 Nov 2016, 16:09

Re: ImagePut - Windows Image Transformation Library

Post by SpeedMaster » 28 Oct 2020, 20:26

iseahound wrote:
27 Oct 2020, 11:49
You can actually use the base64 data directly.
Great, I didn't know that. :thumbup:
iseahound wrote:
27 Oct 2020, 11:49
Cool usage!
Thanks, but I noticed that the cursor changes sometimes for ex. when i read pdfs files and there is no way to force it to stay on the arrow. :cry:
A simple way I have to solve this problem is to make a GUI appear as a transparent layer. I also ensured that the invisible gui does not occupy the whole screen. (so that I keep access to the menu and scroll bars) and this GUI is also temporarily disabled to allow zooming with the mouse wheel. 8-)
Here is the new script with these features. It's a bit messy but it works pretty well. :roll:

Code: Select all

; Script name: Toggle Big Cursor
; version: 1.2
; Shortcuts:  press Win + F1 to toggle a big yellow cursor
;             press F2 to toggle a transparent overlay GUI (to force cursor to stay on the arrow)
;             press Win + Esc to exit the script

#SingleInstance force

#include imageput.ahk

onexit,exit

Base64ImageData=
(
 iVBORw0KGgoAAAANSUhEUgAAADAAAABICAYAAACwc3YrAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAOwgAADsIBFShKgAAAABp0RVh0U29mdHdhcmUAUGFpbnQuTkVUIHYzLjUuMTFH80I3AAAFDUlEQVRoQ9WaSUwsVRSGmR8qgTDIJAlBEBY47Ygx0RBxwRAWroAgIbJgo8HniKjIDhMWJmwxYYYFYcYYXTstnJa6eRtduDEahxf1Rcv/r+ReD/VOSXfV7erqP/mSl+5b957v3lP9mu4uQt4Cd/IfhZrfQUFLeMBIFGQoYCjIk5ACPIlFUFASUkBKFEyCAoaCOQlbdHl5uRQomHayRU9MTHgNDQ1S4jfwJkh1bMEHBweed/Oa19raKiUIJVJ7ErZQI0BCTiKVEqrA/v6+JvEGSF1UAYPSTpRI1UnY4jQBUl9fLwXMSaRG4koBtpMi8TpIRa4UMCjtRIk7QF5jC7pK4OLiIuwk8iqRsQDZ29vTJBZA3pKVAOFJtLS0SAlCibychC0iUwFyfn4edhKJS0QSILu7u5rEayDRRBYgPAmlnSiR2EnYhaMIEErU1dVJgUTbKbYA2dnZ0STmQc7jRICcnZ15zc3NUoJQIqcnYReLK0AoETiJX0FOJZwKkO3tbU3iVZCTOBcgp6enWjtRwvlJ2AVcChBKJNFOORMgW1tbmsQrwFlyKkBC2okSTk7CTporARLSTk7uiUQESEg7vQxiJTEBcnJyorUTJSKfhJ0oCQFCiZAbuxJkncQFyObmpibxEsg6eREgx8fHXlNTk5QglMjqJOzFSQsQStTW1koBc2NnL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mCC
)


Gui -Caption +ToolWindow +AlwaysOnTop +LastFound
WinSet Transparent, 1

#f1::
toggle:=!toggle
if toggle
ImagePutCursor(Base64ImageData, 0, 0) ; x, y hotspots
else
DllCall("SystemParametersInfo", "uint", 0x57, "uint", 0, "ptr", 0, "uint", 0)
return

F2:: % (toggle2:=!toggle2) ? showgui() : hidegui()

~^wheelup::
~^wheeldown::
~wheelup::
~wheeldown::
hidegui()
if (toggle2) {
       sleep, 1000
       showgui()
}
return


showgui() {
      Gui Show, % " y60  w" a_screenwidth-30 " h" a_screenheight-50
}

hidegui() {
      Gui hide,
}

exit:
DllCall("SystemParametersInfo", "uint", 0x57, "uint", 0, "ptr", 0, "uint", 0)
#esc::exitapp
return

Shortcuts:
Win + F1 to toggle a big yellow cursor
F2 to toggle a transparent overlay GUI (to force cursor to stay on the arrow)
Win + Esc to exit

Maybe there is an easier way to force the cursor to show the arrow. :problem:
Cheers

iseahound
Posts: 1427
Joined: 13 Aug 2016, 21:04
Contact:

Re: ImagePut - Windows Image Transformation Library

Post by iseahound » 28 Oct 2020, 21:33

SpeedMaster wrote:
28 Oct 2020, 20:26
iseahound wrote:
27 Oct 2020, 11:49
You can actually use the base64 data directly.
Great, I didn't know that. :thumbup:
How do I explain that better in the documentation? You can use literally anything as an input.

iseahound
Posts: 1427
Joined: 13 Aug 2016, 21:04
Contact:

Re: ImagePut - Windows Image Transformation Library

Post by iseahound » 14 Jan 2021, 12:04

Added a small demonstration file to help first time users with getting used to the library.

Releases: https://github.com/iseahound/ImagePut/releases
Direct Download: https://github.com/iseahound/ImagePut/releases/download/r2021.01.14/ImagePut.v1.zip

Unzip and run demo.ahk

tuzi
Posts: 223
Joined: 27 Apr 2016, 23:40

Re: ImagePut - Library for moving image data on Windows

Post by tuzi » 11 Aug 2021, 10:22

Thank you, @iseahound.
This is the best library I've ever used for image loading, display, and conversion.
So useful, makes everything easy, I love it!

william_ahk
Posts: 470
Joined: 03 Dec 2018, 20:02

Re: ImagePut - Library for moving image data on Windows

Post by william_ahk » 15 Aug 2021, 00:28

For ImagePutWindow, it would be really helpful for the window to be responsive to the screen size.

iseahound
Posts: 1427
Joined: 13 Aug 2016, 21:04
Contact:

Re: ImagePut - Image library for converting to files, streams, windows, base64, urls, cursors, screen coordinates, clipb

Post by iseahound » 07 Oct 2021, 18:49

Big Update

ImagePut v1.2 has been released!
https://github.com/iseahound/ImagePut/releases

I don't normally post release notes in the v1 forum, since we should all be slowly migrating to v2. However, this version contains so many bugfixes and optimizations, that upgrading is a must. I have verified that every conversion works, and have taken steps to ensure that there are no bugs. This release offers stability and speed. As my understanding of Windows API increases, so does my coding ability.

Notably, it is being used by PaddleOCR which is why there are so many optimizations. See here: viewtopic.php?f=6&t=94856

ImagePut was originally developed from some code I was using to convert images to files and base64. That was an old project that also did OCR, called Vis2. So it's kind of going back to its roots as a front-end for OCR. Very cool :bravo:

@william_ahk Sorry not this release, ImagePutWindow needs a lot of work, I promise it'll happen next release. It looks great and seems like it works well, but ImagePutWindow is a function I wrote out of frustration and just published it in some haphazard form.

Release Notes
Support for streams as a intermediate has been added to base64, file, hex, RandomAccessStream, stream, and url. Previously, ImagePutFile(url) would convert via: url → decode → pixels → encode → file. Now it can directly convert: url → stream → file.
  • Increase speed by skipping encoding and decoding of compressed images when using streams.
  • File hashes are now preserved when moving between stream compatible data types.
  • File extensions are also preserved from the input where possible.
  • For previous behavior, the flag ForceDecodeImagePixels has been added.
  • An additional flag, ForcePushImageToMemory controls whether pBitmaps should load their pixel data immediately.
ImageEqual has been completely revamped.
  • Will now throw errors if supplied with an improper image.
  • Calling with one image parameter will now verify that image is valid. Previously, ImageEqual(image) always returned true.
  • Bitmaps are now cloned to solve the problem where multiple calls to LockBits would fail, if the bitmaps shared the same stream. Calling LockBits from the clone will lock the original bitmap so the underlying stream is never locked.
  • CloneImage has been replaced with GdipCloneBitmapAreaI to preserve the native PixelFormat when cloning.
  • Support for bitmaps with negative stride is implicit when cloning.
Bugfixes
  • Declared types {type:image} were broken by v1.1.
  • A 24-bit image passed to put_clipboard would cause the script to crash.
  • Some applications expected a bottom-up bitmap from the clipboard.
  • Not supplying a valid window handle to OpenClipboard would cause EmptyClipboard to crash.
  • Calling ObjRelease() on a clipboard stream would delete the clipboard data.
  • select_codec() now throws instead of defaulting to PNG.
Internal Documentation
  • from_XX and put_XX has been factored into get_XX and set_XX if the function used a stream.
  • There are two types of streams: pStream from CreateStreamOnHGlobal and pMemoryStream from SHCreateMemStream.
  • Calls to SHCreateMemStream (pMemoryStream) have been removed as GetHGlobalFromStream is only supported on pStreams.
  • All get_XX functions create pStreams. All set_XX functions read both pStream and pMemoryStream.
  • Multiple bitmaps created on a single stream are now resolved by calling either GdipImageForceValidation through the ForcePushImageToMemory flag, or by calling GdipCloneImage on a given pBitmap.
  • put_screenshot now uses bilinear scaling.
  • put_screenshot defaults to the top left corner of the screen.
  • Return values of uint have been replaced with HRESULT in v2.


iseahound
Posts: 1427
Joined: 13 Aug 2016, 21:04
Contact:

Re: ImagePut - Image library for converting to files, streams, windows, base64, urls, cursors, screen coordinates, clipb

Post by iseahound » 07 Oct 2021, 21:18

@william_ahk Out of curiosity, would something like a double click to close window be nice? left/right click?

william_ahk
Posts: 470
Joined: 03 Dec 2018, 20:02

Re: ImagePut - Image library for converting to files, streams, windows, base64, urls, cursors, screen coordinates, clipb

Post by william_ahk » 07 Oct 2021, 22:04

@iseahound Yes this can be very useful for borderless windows, double left click to close the window is a very common implementation.

iseahound
Posts: 1427
Joined: 13 Aug 2016, 21:04
Contact:

Re: ImagePut - Image library for converting to files, streams, windows, base64, urls, cursors, screen coordinates, clipb

Post by iseahound » 10 Oct 2021, 19:29

Updated first post. Added a simple right click to close the window. ImagePutWindow now responds to the screen size. However, I did not have the time to completely revamp ImagePutWindow, so it (just works)™.
Note to self

tuzi
Posts: 223
Joined: 27 Apr 2016, 23:40

Re: ImagePut - Image library for converting to files, streams, windows, base64, urls, cursors, screen coordinates, clipb

Post by tuzi » 14 Oct 2021, 07:19

I wrote a Chinese version of the tutorial.

这里有一个中文版的使用教程。

https://www.autoahk.com/archives/37246

iseahound
Posts: 1427
Joined: 13 Aug 2016, 21:04
Contact:

Re: ImagePut - Image library for converting to files, streams, windows, base64, urls, cursors, screen coordinates, clipb

Post by iseahound » 14 Oct 2021, 11:23

Great tutorial! :bravo:

Edit: I added it to the github page. I can only speak chinese so I just copied your sentence. :lol:

Post Reply

Return to “Scripts and Functions (v1)”