Page 3 of 4

Re: Imagen() : A fade-in/fade-out animator for picture control

Posted: 18 Jun 2021, 16:02
by SKAN
SKAN wrote:
18 Jun 2021, 05:57
That is how things work in windows unless you use a layered window.
Ok @pv007. Thought I should write a demo and see it for myself.
I won't include this in Imagen() as Windows 7 doesn't support WS_EX_LAYERED for controls.

Code: Select all

#NoEnv
#Warn
#SingleInstance, Force
SetWorkingDir, %A_ScriptDir%
SetBatchLines, -1


; Fade in/out a picture on layered control
; This script requires Windows OS v8.0 or higher

#NoEnv
#Warn
#SingleInstance, Force
SetWorkingDir, %A_ScriptDir%
SetBatchLines -1
If ! FileExist("pkf.jpg")
     UrlDownLoadToFile
   , http://www.indianaturewatch.net/images/album/photo/7700105755c69b2d6e684a.jpg
   , pkf.jpg

Gui, New,, Fade-in / Fade-out
Gui, Margin, 20, 20
Gui, Add, Text, w1020 h680 hwndhPic +E0x80000 ; WS_EX_LAYERED
Gui, Show,, % "Fade-in / fade-out demo " (A_PtrSize=8 ? "x64" : "x86")
Sleep 500

hBM := LoadPicture("pkf.jpg", "GDI+")
mDC := DllCall("CreateCompatibleDC", "Ptr",0, "Ptr")
DllCall("SaveDC", "Ptr",mDC)
DllCall("SelectObject", "Ptr",mDC, "Ptr",hBM)

VarSetCapacity(SIZE, 8, 0)
NumPut(1020, SIZE, "int")
NumPut(680, SIZE, 4, "int")

VarSetCapacity(BLENDFUNCTION, 4, 0)
NumPut(1, BLENDFUNCTION, 3, "UChar")

SetBatchLines 1

Loop 255
DllCall("UpdateLayeredWindow", "Ptr",hPic, "Ptr",0, "Ptr",0
      , "Ptr",&SIZE, "Ptr",mDC, "Int64P",0, "Int",0
      , "Ptr", NumPut(A_Index, BLENDFUNCTION, 2, "UChar") - 3
      , "Int", 2)

Sleep 2000

Loop 254
DllCall("UpdateLayeredWindow", "Ptr",hPic, "Ptr",0, "Ptr",0
      , "Ptr",&SIZE, "Ptr",mDC, "Int64P",0, "Int",0
      , "Ptr", NumPut(255-A_Index, BLENDFUNCTION, 2, "UChar") - 3
      , "Int", 2)

DllCall("RestoreDC", "Ptr",mDC, "Int",-1)
DllCall("DeleteDC", "Ptr",mDC)
Return

GuiEscape:
GuiClose:
 ExitApp

Re: Imagen() : A fade-in/fade-out animator for picture control

Posted: 21 Jun 2021, 13:08
by SKAN
iseahound wrote:
17 Jun 2021, 09:05
You may get strange edges when upscaling so in the ImageAttributes set WrapModeTileFlipXY.
That way when upscaling is preformed it will sample mirrored pixels instead of pure black.
That was a great tip!. Thank you very much. :thumbup:
About readability: Re-formatting code with better indentation and some comments.

Re: Imagen() : A fade-in/fade-out animator for picture control

Posted: 28 Jun 2021, 18:21
by fenchai
wow this is one sick lib. thanks a lot

Re: Imagen() : A fade-in/fade-out animator for picture control

Posted: 29 Jun 2021, 04:36
by SKAN
fenchai wrote:
28 Jun 2021, 18:21
wow this is one sick lib. thanks a lot
Thanks for trying.. and for the feedback. :) :thumbup:

Re: Imagen() : A fade-in/fade-out animator for picture control

Posted: 02 Jul 2021, 15:43
by fenchai
I was thinking... is it possible to have options like rotate to the left, right, top, bottom (-180, 180, 90... etc)
So far, enjoying the fading options a lot!, I really hope there was some kind of documentation for all the options, maybe there is and I haven't found it.

Re: Imagen() : A fade-in/fade-out animator for picture control

Posted: 04 Jul 2021, 14:08
by SKAN
fenchai wrote:
02 Jul 2021, 15:43
I was thinking... is it possible to have options like rotate to the left, right, top, bottom (-180, 180, 90... etc)
I've mention here the specific uses for imagen().
https://www.autohotkey.com/boards/viewtopic.php?p=405583#p405583
 
I feel it would spoil this function by trying to do everything in a single function.
fenchai wrote:
02 Jul 2021, 15:43
So far, enjoying the fading options a lot!, I really hope there was some kind of documentation for all the options, maybe there is and I haven't found it.
I've been meaning to post proper documentation, but everything has been included in examples.

Re: Imagen() : A fade-in/fade-out animator for picture control

Posted: 05 Jul 2021, 08:59
by fenchai
I see, it is still a great function, I have learned a lot just by looking on your list examples. Thanks a lot for your work.

Re: Imagen() : A fade-in/fade-out animator for picture control

Posted: 09 Jul 2021, 16:15
by c7aesa7r
@SKAN Im using Imagen() to set transparency on some bitmaps and drawing text over the images with GdipDrawString, i dont want to also apply the transparency on the text, i would like to ask if you know ifs possible to draw the text after the transparency has been applied to the image.

Im reading your function but i cant figure if its possible, and if so, where i should add the code to draw the text before the image is converted to a HBITMAP.

Re: Imagen() : A fade-in/fade-out animator for picture control

Posted: 10 Jul 2021, 02:20
by SKAN
c7aesa7r wrote:
09 Jul 2021, 16:15
Im reading your function but i cant figure if its possible, and if so, where i should add the code to draw the text before the image is converted to a HBITMAP.
In current v3.22, @ line 199.

Re: Imagen() : A fade-in/fade-out animator for picture control

Posted: 21 Jul 2021, 13:18
by c7aesa7r
@SKAN, i was 'benchmarking' the speed of your Imagen function, i have changed:

Code: Select all

  If (StrLen(X)!=200 )
  Switch ( X ) {
  Default          : X := ""
  Case "Normal"    : X := "0000803f00000000000000000000000000000000000000000000803f0000000000000000000000000000000000"
    . "0000000000803f00000000000000000000000000000000000000000000803f00000000000000000000000000000000000000000000803f"
  Case "Grayscale" : X := "8716993e8716993e8716993e0000000000000000a245163fa245163fa245163f0000000000000000d578e93dd5"
    . "78e93dd578e93d00000000000000000000000000000000000000000000803f00000000000000000000000000000000000000000000803f"
  Case "Invert"    : X := "000080bf0000000000000000000000000000000000000000000080bf0000000000000000000000000000000000"
    . "000000000080bf00000000000000000000000000000000000000000000803f000000000000803f0000803f0000803f000000000000803f"
  Case "Sepia"     : X := "4c37c93e21b0b23e96438b3e00000000000000002fdd443fb29d2f3f39b4083f00000000000000003789413e31"
    . "082c3edd24063e00000000000000000000000000000000000000000000803f00000000000000000000000000000000000000000000803f"
  }

  If ( StrLen(X)=200 && VarSetCapacity(CM,100,0) )
  {
   X:=DllCall("Crypt32.dll\CryptStringToBinary", "Str",X, "Int",200, "Int",4, "Ptr",&CM, "IntP",100, "Int",0, "Int",0)

to

Code: Select all

   ; Normal
   X :=  "0000803f00000000000000000000000000000000000000000000803f00000000000000000000  000000000000000000000000803f00000000000000000000000000000000000000000000803f0   0000000000000000000000000000000000000000000803f"
   
   VarSetCapacity(CM,100,0)
   X:=DllCall("Crypt32.dll\CryptStringToBinary", "Str",X, "Int",200, "Int",4,    "Ptr",&CM, "IntP",100, "Int",0, "Int",0)
This is the part of the code that consume some time, most possible in that dllcall.

As i'll be always using the same color matrix (normal)
Is possible to convert it in something that doesn't involve that dllcall?
I called NumGet in the value of X:=DllCall and it always return the same value, maybe adding this value with Numput in the value of CM?
I dont understand how to properly add the value of X inside CM and if it would work. :think:

Re: Imagen() : A fade-in/fade-out animator for picture control

Posted: 21 Jul 2021, 13:58
by SKAN
c7aesa7r wrote:
21 Jul 2021, 13:18
Is possible to convert it in something that doesn't involve that dllcall?
I called NumGet in the value of X:=DllCall and it always return the same value, maybe adding this value with Numput in the value of CM?
I dont understand how to properly add the value of X inside CM and if it would work. :think:
Hi,
If you are changing the function please rename it. Even a subtle change in function name would be enough. Thanks.

The following should work:

Code: Select all

Alpha := 255
VarSetCapacity(CM, 100, 0)
NumPut(1, CM,  0, "Float")
NumPut(1, CM, 24, "Float")
NumPut(1, CM, 48, "Float")
NumPut(1, CM, 96, "Float")
NumPut(Alpha/255, CM, 72, "Float")
X := 1

Re: Imagen() : A fade-in/fade-out animator for picture control

Posted: 23 Jan 2022, 18:39
by pv007
SKAN wrote:
18 Jun 2021, 16:02
Ok @pv007. Thought I should write a demo and see it for myself.
I won't include this in Imagen() as Windows 7 doesn't support WS_EX_LAYERED for controls.
SKAN im trying to run your example but nothing happens, the GUI is entire blank, the image was downloaded successfully, also tested with other images, same result.
Tested on win10.

Re: Imagen() : A fade-in/fade-out animator for picture control

Posted: 24 Jan 2022, 02:39
by SKAN
pv007 wrote:
23 Jan 2022, 18:39
SKAN im trying to run your example but nothing happens, the GUI is entire blank, the image was downloaded successfully, also tested with other images, same result.
Tested on win10.
No idea.

I tested again.
Win 7: "Can't create control" error.
Win 10: :thumbup:
Win 11 : :thumbup:

Re: Imagen() : A fade-in/fade-out animator for picture control

Posted: 25 Jan 2022, 13:43
by pv007
The script works when i run it with AutoHotkeyU32 but no U64, it's an x32 version only?

Re: Imagen() : A fade-in/fade-out animator for picture control

Posted: 25 Jan 2022, 13:57
by SKAN
pv007 wrote:
25 Jan 2022, 13:43
it's an x32 version only?
Fixed. Sorry!
I was using the wrong hotkey in editor.
I was testing U32 and A32 while it should have been U32 and U64
Added bitness to caption and fixed couple of numputs

Code: Select all

NumPut(1020, SIZE, "int")
NumPut(680, SIZE, 4, "int")

Re: Imagen() : A fade-in/fade-out animator for picture control

Posted: 25 Jan 2022, 18:44
by pv007
Thanks SKAN perfect now, do you know how to make good rounded border pictures?
I have found some functions in the forum but none give a good result.

Something like this:
Spoiler

Re: Imagen() : A fade-in/fade-out animator for picture control

Posted: 26 Jan 2022, 13:06
by SKAN
pv007 wrote:
25 Jan 2022, 18:44
do you know how to make good rounded border pictures?
Haven't tried yet.
I don't code in V1 anymore.. Not very experienced in V2, yet.
I might create a graphics lib for V2 in which this would be a component.

Re: Imagen() : A fade-in/fade-out animator for picture control

Posted: 26 Jan 2022, 18:40
by Chappier
Is not possible to use other pixel format than 0xE200B? I tested setting transparency on a png with 200kb and then save it, the saved picture is now 3.5mb.
Tried to change the line PARGB := 925707 to another format like 0x21005 but it resulted in a saved picture without any transparency, the image just got darker.

Re: Imagen() : A fade-in/fade-out animator for picture control

Posted: 27 Jan 2022, 01:32
by SKAN
@Chappier

Is your question related to Imagen()
I tested setting transparency on a png with 200kb
Image dimensions?

Re: Imagen() : A fade-in/fade-out animator for picture control

Posted: 27 Jan 2022, 01:57
by malcev
Chappier, use wic or custom algorithms.
Long discussion here:
viewtopic.php?f=76&t=94345