ToGrayscale() : Converts GDI bitmap to Greyscale

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
KruschenZ
Posts: 45
Joined: 20 Jan 2021, 07:05
Location: Germany (Rheinhessen)
Contact:

Re: ToGrayscale() : Converts GDI bitmap to Greyscale

02 Jul 2021, 08:29

Hello there :-)

very nice function! Thanks for that!

I have some questions:
  • 1) Is it possible to not change the alpha channel (transparency) from an .DLL - Icon-File?
  • 2) Or is it possible to change the "new black" color to transparency or to the background color from the button?

Code: Select all

Gui, % "Test:Add", Picture, % " xp yp HwndH_Icon_2 wp hp +BackgroundTrans +AltSubmit", % "HBITMAP:" . ToGrayscale( LoadPicture(UserConfig_IconsDLL, "GDI+ w16 h-1 Icon" . This.Icon, 1) )

examples:
active / enabled button:
grafik.png
grafik.png (1.25 KiB) Viewed 1908 times
inactive / disabled button (with the ToGrayscale-function):
grafik.png
grafik.png (1.27 KiB) Viewed 1908 times

Thank you very much.

Best regards
KruschenZ ;-)
User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

Re: ToGrayscale() : Converts GDI bitmap to Greyscale

04 Jul 2021, 13:54

KruschenZ wrote:
02 Jul 2021, 08:29
I have some questions:
  • 1) Is it possible to not change the alpha channel (transparency) from an .DLL - Icon-File?
  • 2) Or is it possible to change the "new black" color to transparency or to the background color from the button?
Hi @KruschenZ
This GDI based function returns 256 color bitmap. For preserving alpha, we need to use GDI+.
Imagen() can do this and more, if you don't mind an elaborate function.
If you need help with it, please post in that topic.
User avatar
KruschenZ
Posts: 45
Joined: 20 Jan 2021, 07:05
Location: Germany (Rheinhessen)
Contact:

Re: ToGrayscale() : Converts GDI bitmap to Greyscale

06 Jul 2021, 09:59

Hi @SKAN,

thank you for the tip :)

it works perfect. :clap:

Code: Select all

Imagen( "HBITMAP:" . LoadPicture(UserConfig_IconsDLL, "GDI+ w" . This.GUI_Control_Size . " h-1 Icon" . This.Icon, 1), "?Grayscale BackgroundTrans ahk_id" . H_Icon_2)


Thank you very much. :)

Best regards
KruschenZ
User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

Re: ToGrayscale() : Converts GDI bitmap to Greyscale

07 Jul 2021, 00:51

KruschenZ wrote:
06 Jul 2021, 09:59
it works perfect. :clap:
Thanks for the feedback. :)
Kotte
Posts: 46
Joined: 03 May 2021, 08:33

Re: ToGrayscale() : Converts GDI bitmap to Greyscale

07 Feb 2022, 15:18

@SKAN Haha, it's crazy how many good and fun functions you produce!! I have had many hours of fun (since finding AutoHotkey about nine months ago) going through your list and I just got to this last one.. On page one of five :D My initial thought when seeing this was "why not just the snipping tool?", but I quickly realized that there are many situations where you just want it readily available in a script. I have no idea how you guys compared the images, but if you are willing to have a look at "my" image as well, I'd be very curious to find out how it stacks up. I just used the built in Ctrl + Win + C to turn off the colours and then the snipping tool.
Image
Regardless of if you compare them or not, I would like to thank you for the work you put in. Your DesktopIcons function was the first function that I got working and It has been in my main script ever since. I can't remember how many of your functions that I still use (don't worry your comments/tags are left in my scripts so I know who I have to thank when i see them :) ), but as recently as the previous few hours I've been playing around with your TextToPic function, trying to build a simple semi transparent remainder with it. I'll probably still be discovering new things from your library for years to come.

It's too bad this forum doesn't have tip jars or up voting (like SE). Until it does I at least extend my deepest gratitude. Keep up the good work! :thumbup:
User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

Re: ToGrayscale() : Converts GDI bitmap to Greyscale

08 Feb 2022, 13:01

Thanks for the nice words @Kotte :thumbup:
Finallf
Posts: 18
Joined: 30 Oct 2020, 13:52

Re: ToGrayscale() : Converts GDI bitmap to Greyscale

28 Feb 2022, 03:25

@SKAN
I'm using AHKv2

can port to AHKv2 ?

I would be very grateful :D
User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

Re: ToGrayscale() : Converts GDI bitmap to Greyscale

28 Feb 2022, 15:25

Finallf wrote:
28 Feb 2022, 03:25
@SKAN
I'm using AHKv2

can port to AHKv2 ?

I would be very grateful :D
The method used in this function is a hack and doesn't produce great results.
I will write and post a machine code V2 version which should produce better results.
Finallf
Posts: 18
Joined: 30 Oct 2020, 13:52

Re: ToGrayscale() : Converts GDI bitmap to Greyscale

28 Feb 2022, 22:15

SKAN wrote:
28 Feb 2022, 15:25
Finallf wrote:
28 Feb 2022, 03:25
@SKAN
I'm using AHKv2

can port to AHKv2 ?

I would be very grateful :D
The method used in this function is a hack and doesn't produce great results.
I will write and post a machine code V2 version which should produce better results.
Even being a "Hack" as you are talking, in my humble opinion, it was very good.
And best of all, it's a small and simple code, so it should be very fast.
Anyway, I'm looking forward to seeing your new code using machine code.
User avatar
thqby
Posts: 431
Joined: 16 Apr 2021, 11:18
Contact:

Re: ToGrayscale() : Converts GDI bitmap to Greyscale

01 Mar 2022, 01:59

viewtopic.php?f=83&t=98385

@Finallf
In V2 version, this library can also be converted to grayscale images and threshold conversion.
ottowa
Posts: 1
Joined: 03 Mar 2024, 17:06
Contact:

Re: ToGrayscale() : Converts GDI bitmap to Greyscale

03 Mar 2024, 18:06

Hi @SKAN, thank you for your work, I know next to nothing about AHK but your script (used in @WeedTrek's XP shutdown dialog) helped me greatly for customizing my Windows 10 and 11 to look like XP! :P I have a concern/request regarding the greyscale script's compatibility with Windows 11. I ran your script demo in Windows 11 and got this:
AutoHotkey_Zj58WaosPp.png
AutoHotkey_Zj58WaosPp.png (74.24 KiB) Viewed 215 times
As you can see there are black artifacts in the image. Is there a way to fix this issue? And yes this is Windows 11 with a Windows 98 skin :D . I get the same result with the skin turned off.

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 35 guests