How to perfectly fit any image on a fixed size picture control

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

How to perfectly fit any image on a fixed size picture control

20 Jul 2017, 18:39

    Image

Run the code and drop images ( including icons,DLL, EXE ) on the GUI

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

scriptor2016
Posts: 282
Joined: 21 Dec 2015, 02:34

Re: How to perfectly fit any image on a fixed size picture control

20 Jul 2017, 23:58

Line 12 returns an error:

Call to non existent function.
hBM := LoadPicture( File )

where can we get that function?
carno
Posts: 83
Joined: 20 Jun 2014, 16:48

Re: How to perfectly fit any image on a fixed size picture control

25 Jul 2017, 10:30

Works perfectly!
AutoHotkey : v1.1.24.04 Unicode 32-bit (Installed)
SystemOS : WIN_XP 32-bit Service Pack 2 v5.1.2600 (WIN32_NT)
User avatar
Drugwash
Posts: 315
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania
Contact:

Re: How to perfectly fit any image on a fixed size picture control

28 Jul 2017, 09:37

AHK is awful at resizing very large images to very small sizes. (example)

Does anybody know of a fast and efficient resizing algorithm usable with AHK that produces results similar to the right picture in the example? (resized with FastStone Image Viewer, using default Lanczos algorithm - most notable difference is the title in white)
gwarble
Posts: 220
Joined: 30 Sep 2013, 15:01

Re: How to perfectly fit any image on a fixed size picture control

28 Jul 2017, 11:16

its a limitation of GDI/GDI+ from what I understand, you have to roll your own
https://www.codeproject.com/Articles/11 ... erform-GDI
EitherMouse - Multiple mice, individual settings . . . . www.EitherMouse.com . . . . forum . . . .
User avatar
SKAN
Posts: 310
Joined: 29 Sep 2013, 16:58

Re: How to perfectly fit any image on a fixed size picture control

29 Jul 2017, 17:33

gwarble wrote:its a limitation of GDI/GDI+ from what I understand, you have to roll your own
https://www.codeproject.com/Articles/11 ... erform-GDI


Thanks for the link.
There is a 32bit DLL based on that code
Plain C Resampling DLL : https://www.codeproject.com/Articles/22 ... mpling-DLL

Wish AHK have this incorporated.. Not sure if CPOL License is compatible with GPL v2

:)
User avatar
SKAN
Posts: 310
Joined: 29 Sep 2013, 16:58

Re: How to perfectly fit any image on a fixed size picture control

29 Jul 2017, 17:37

Drugwash wrote:Does anybody know of a fast and efficient resizing algorithm usable with AHK that produces results similar to the right picture in the example? (resized with FastStone Image Viewer, using default Lanczos algorithm - most notable difference is the title in white)


Here we go:

    Image

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

Attachments
ResampleDLL.zip
(53.8 KiB) Downloaded 42 times
User avatar
Drugwash
Posts: 315
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania
Contact:

Re: How to perfectly fit any image on a fixed size picture control

29 Jul 2017, 19:15

Thank you both. Few years ago I actually read that article but the code was (and still is) unusable for me with AHK Basic.
I'll test the Resample library soon; now it's 3AM and gotta go to sleep.
However until now I fought with gdiplus and found out it can produce higher quality output when appropriate settings are made.
Also certain versions of gdiplus (currently I have 11 versions for testing) may produce different results with the same settings.
Contrary to opinions found on the web, gdiplus v6.0 does work in Win9x and effects are applied correctly (at least on my system). Just tested blur minutes ago.
I'll be back with details and screenshots.
arcticir
Posts: 473
Joined: 17 Nov 2013, 11:32

Re: How to perfectly fit any image on a fixed size picture control

29 Jul 2017, 23:00

Using GDI to draw controls has a nice effect.

Image
User avatar
SKAN
Posts: 310
Joined: 29 Sep 2013, 16:58

Re: How to perfectly fit any image on a fixed size picture control

30 Jul 2017, 01:53

arcticir wrote:Using GDI to draw controls has a nice effect.


Looks nice... Post some code, please!.
arcticir
Posts: 473
Joined: 17 Nov 2013, 11:32

Re: How to perfectly fit any image on a fixed size picture control

30 Jul 2017, 02:21

I did not save the test code, so I rewrote one. It needed H2.

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

HotKeyIt
Posts: 1551
Joined: 29 Sep 2013, 18:35
Contact:

Re: How to perfectly fit any image on a fixed size picture control

30 Jul 2017, 03:51

I have optimized the code above for AHK_H v2 a little bit ;)

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

User avatar
Drugwash
Posts: 315
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania
Contact:

Re: How to perfectly fit any image on a fixed size picture control

30 Jul 2017, 14:37

What language is that above…? I can't read it.
Honestly, that's not the AHK I once knew. But forget that.

The only way I could get XP to actually use the specific version of gdiplus I wanted was to modify the AHK exe manifest. 98SE has no shame in loading and using whatever library I feed it. Unfortunately 98 has a problem in manipulating and displaying the alpha channel. Not that it matters for any of you.

The highest "official" version of gdiplus on my XP is 5.2.6002.23846 and although it's branded "vistasp2" it does not have the effects-related API. Those come only with v6.0+ (or as some call it v1.1). Such version can be found in Power Point Viewer, for one or in some newer version of MS Office (Office 13 might have a newer gdiplus 6 that PPViewer).

Enough talking, here's the old-fashioned code; if you get a crash or last image isn't blurred then you need to coerce your AHK into using a specific gdiplus:
code+screenshots (~2.8MB)

Screenshots are in the package because the board resizes images and destroys their quality. Both screenshots were captured in 98SE, the one using gdiplus 5.2 can't create blur on last image but image quality for InterpolationMode 5 is visibly better than with v6 (compare the white text).
User avatar
SKAN
Posts: 310
Joined: 29 Sep 2013, 16:58

Re: How to perfectly fit any image on a fixed size picture control

31 Jul 2017, 17:00

Thanks arcticir and HotKeyIt. :)

@HotKeyIt

Doesn't AHK use GDI+ Smoothing / Interpolation settings?!
Or does it use GDI+ only to open the image and then use CopyImage() to resize?
Please confirm.
User avatar
SKAN
Posts: 310
Joined: 29 Sep 2013, 16:58

Re: How to perfectly fit any image on a fixed size picture control

31 Jul 2017, 17:59

HotKeyIt wrote:As far as I can see it uses CopyImage to resize


Ah.. I see.. Disappointing . :(
Thanks for the confirmation.
User avatar
SKAN
Posts: 310
Joined: 29 Sep 2013, 16:58

Re: How to perfectly fit any image on a fixed size picture control

01 Aug 2017, 02:11

Drugwash wrote:here's the old-fashioned code; if you get a crash or last image isn't blurred then you need to coerce your AHK into using a specific gdiplus:
code+screenshots (~2.8MB)


Excellent! Thanks for sharing Drugwash. :)
Can you explain what the last parameter does?. Won't 0xFFFFFFFF mess up a PNG with semitransparent pixels?

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

		DllCall("gdiplus\GdipCreateHBITMAPFromBitmap"
, Ptr, pB
, PtrP, hBmp%A_Index%
, "Int", 0xFFFFFFFF)
User avatar
jNizM
Posts: 2295
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: How to perfectly fit any image on a fixed size picture control

01 Aug 2017, 03:11

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

GdipCreateHBITMAPFromBitmap(GpBitmap* bitmap, HBITMAP* hbmReturn, ARGB background)

bitmap -> [in] Pointer to the Bitmap object.
hbmReturn -> [out] Pointer to an HBITMAP that receives a handle to the GDI bitmap.
background -> [in] ARGB color that specifies the background color. This parameter is ignored if the bitmap is totally opaque.
[AHK] 1.1.26.01 x64 Unicode | [WIN] 10 Pro (Version 1703) x64
My GitHub Profile | Donations are appreciated if I could help you
User avatar
Drugwash
Posts: 315
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania
Contact:

Re: How to perfectly fit any image on a fixed size picture control

01 Aug 2017, 03:18

@ SKAN: You're welcome. :)

Honestly, part of the code I found here and there on the web, didn't get documented much about all API.
In regard to the one you mentioned I don't think it breaks anything, i tried the same script with logo.png (same AHK logo used in yours and arcticir's examples) and it displayed it properly in XP (apart from bad aspect ratio); only 98 has problems (transparent background was displayed blue instead).

Return to “Scripts and Functions”

Who is online

Users browsing this forum: No registered users and 13 guests