@SKAN
Thank you skan!
Because of the library you shared, it inspired me to make the 1.0 version of the photo filtering tool, and then I learned GDI+ and solved the problem!
Thank you very much for sharing. I believe they are the cornerstone of success for many people, including me.
Imagen() : A fade-in/fade-out animator for picture control
-
- Posts: 222
- Joined: 07 Mar 2021, 07:44
Re: Imagen() : A fade-in/fade-out animator for picture control
Imagen works great here. I have a question for @SKAN though.
Does it manage transparency with multiple images ?
I'm currently trying to display a png with transparent background over a jpg.
I can display the jpg, I can display the png, but when I display the png over the jpg I can't see the jpg anymore.
AHK default method with BackgroundTrans works well, I can display one image over the other, but scaling quality is very poor of course.
Here's what I'm currently doing :
ImgBack is the location of a jpg background.
ImgLoc is the location of a png with transparent background.
I have tried with and without BackgroundTrans.
Or should I place only one Imagen call just before the Gui, Show ? But then what Hwnd should I pass ? I'm not sure I understand everything.
Does it manage transparency with multiple images ?
I'm currently trying to display a png with transparent background over a jpg.
I can display the jpg, I can display the png, but when I display the png over the jpg I can't see the jpg anymore.
AHK default method with BackgroundTrans works well, I can display one image over the other, but scaling quality is very poor of course.
Here's what I'm currently doing :
Code: Select all
Gui, %ImgGuiName%: Add, Picture, x%BorderWidth% y%BorderWidth% h%WantedHeight% w%WantedWidth% HwndhPic1
Imagen(ImgBack, "ahk_id" . hPic1)
Gui, %ImgGuiName%: Add, Picture, BackgroundTrans x%BorderWidth% y%BorderWidth% h%WantedHeight% w%WantedWidth% HwndhPic2
Imagen(ImgLoc, "ahk_id" . hPic2)
ImgLoc is the location of a png with transparent background.
I have tried with and without BackgroundTrans.
Or should I place only one Imagen call just before the Gui, Show ? But then what Hwnd should I pass ? I'm not sure I understand everything.
Re: Imagen() : A fade-in/fade-out animator for picture control
Jose Hidalgo wrote: ↑09 Jun 2021, 14:01I'm currently trying to display a png with transparent background over a jpg.
You downloaded the zip, right? Save and try the following example from root folder.
Code: Select all
#NoEnv
#Warn
#SingleInstance, Force
SetWorkingDir, %A_ScriptDir%
SetBatchLines, -1
ImgBack := "Images\Img_0482.jpg"
ImgLoc := "Images\Imagen.png"
Gui, Add, Picture, w600 h400 hwndhPic1
Gui, Add, Picture, xp yp wp hp BackgroundTrans hwndhPic2
Imagen(ImgBack, "ahk_id" . hPic1)
Imagen(ImgLoc, "BackgroundTrans ahk_id" . hPic2)
Gui, Show,, Overlapped picture controls
-
- Posts: 222
- Joined: 07 Mar 2021, 07:44
Re: Imagen() : A fade-in/fade-out animator for picture control
Works perfectly now, it was merely a syntax issue. Thank you, and congrats again for this beaufiful function.
Re: Imagen() : A fade-in/fade-out animator for picture control
in this example, can you fade a new background (ImgBack) image while the front image is in place?
Or more simply, if you have a text control overlaying the image, can you fade a new image without the text disappearing with Imagen()?
Or more simply, if you have a text control overlaying the image, can you fade a new image without the text disappearing with Imagen()?
EitherMouse - Multiple mice, individual settings . . . . www.EitherMouse.com . . . . forum . . . .
Re: Imagen() : A fade-in/fade-out animator for picture control
@gwarble : Seems not possible.
Re: Imagen() : A fade-in/fade-out animator for picture control
seems not, thanks anyway for a great function!
EitherMouse - Multiple mice, individual settings . . . . www.EitherMouse.com . . . . forum . . . .
Imagen() v3.22
The in-built colormatrix presets are now: Grayscale Invert Sepia and Normal.
Any of these presets maybe followed by :Alpha value (0-255) to make the image semitransparent.
Example: ?Grayscale:127.5 will convert the image to Grayscale and make it 50% transparent.
I've added the following example script ( OverlappedPictureControls.ahk ) to the demo:
Any of these presets maybe followed by :Alpha value (0-255) to make the image semitransparent.
Example: ?Grayscale:127.5 will convert the image to Grayscale and make it 50% transparent.
I've added the following example script ( OverlappedPictureControls.ahk ) to the demo:
Code: Select all
#NoEnv
#Warn
#SingleInstance, Force
ImgBack := "Images\Img_0482.jpg"
ImgLoc := "Images\Imagen.png"
Gui, Add, Picture, w600 h400 hwndhPic1
Gui, Add, Picture, xp yp wp hp BackgroundTrans hwndhPic2
Imagen(ImgBack, "ahk_id" . hPic1)
Imagen(ImgLoc, "?Normal:180 BackgroundTrans ahk_id" . hPic2)
Gui, Show,, Overlapped picture controls
Re: Imagen() : A fade-in/fade-out animator for picture control
@SKAN can i request a feature in your function?
Support to specify what region of the picture should be set transparent
This picture 800x300 So if I set Imagen(400,0,400,300) it would return something like this result: Im loading the hBitmap from Imagen() into a DC, so I cant split the image > set transparency in just the desired area > combine them again
Support to specify what region of the picture should be set transparent
This picture 800x300 So if I set Imagen(400,0,400,300) it would return something like this result: Im loading the hBitmap from Imagen() into a DC, so I cant split the image > set transparency in just the desired area > combine them again
Re: Imagen() : A fade-in/fade-out animator for picture control
Hi @pv007
Originally Imagen() was a Slideshow class.
I'm a photographer and I love to fade-in my images from Grayscale to Color.
Its such a pleasure to watch a slideshow in this manner and hence I wrote it for my own use.
The class version was too huge and I thought a trimmed down version would be useful for the community.
These are the intended uses for Imagen()
There are atleast two instances where you have a fixed rectangle and the need to scale down/up your image to fit it.
1) Picture control
2) ImageList
Other than the above, one could use Imagen() to show multiple states of a (picture/button) control.
For example, with a single color image, we could show
Grayscale as Normal, Color on mouse hover, and Inverted when clicked.
This is where I thought Opacity would be a great add.. that is to show a "state".. and hence I added the feature.
I don't intend to bloat the function back to its original size.
Unfortunately our forum doesn't have anything that I would rely on or contribute to.
Originally Imagen() was a Slideshow class.
I'm a photographer and I love to fade-in my images from Grayscale to Color.
Its such a pleasure to watch a slideshow in this manner and hence I wrote it for my own use.
The class version was too huge and I thought a trimmed down version would be useful for the community.
These are the intended uses for Imagen()
There are atleast two instances where you have a fixed rectangle and the need to scale down/up your image to fit it.
1) Picture control
2) ImageList
Other than the above, one could use Imagen() to show multiple states of a (picture/button) control.
For example, with a single color image, we could show
Grayscale as Normal, Color on mouse hover, and Inverted when clicked.
This is where I thought Opacity would be a great add.. that is to show a "state".. and hence I added the feature.
I don't intend to bloat the function back to its original size.
This would be best done as a separate function depending on a gdiplus library.
Unfortunately our forum doesn't have anything that I would rely on or contribute to.
Re: Imagen() : A fade-in/fade-out animator for picture control
Im playing with the examples in the zip, is not possible to fade and after set transparency?
How do I remove a picture added using Imagen ahk_id . control?
Looks like
Cant remove the picture.
How do I remove a picture added using Imagen ahk_id . control?
Looks like
Code: Select all
guicontrol,, hPic
Code: Select all
Gui, New, -Caption +Border
Gui, Color, 505050
Gui, Add, Picture, w400 h500 0x200 HwndhPic
Gui, Show
Sleep 500
Imagen("Images\Imagen.png", "BackgroundTrans Fadein1000ms ahk_id" . hPic)
Sleep 2000
;Imagen("", "BackgroundTrans Fadein1000ms ahk_id" . hPic)
;FileAppend, hPic: %hPic% `n, *
guicontrol,, hPic
Imagen("Images\Imagen.png", "?Normal:150 BackgroundTrans ahk_id" . hPic)
return
esc::ExitApp
Re: Imagen() : A fade-in/fade-out animator for picture control
SKAN, your code is impossibly hard to read and I’m surprised you manage to keep track of it without documentation.
In your upscaling part, you don’t need a SmoothingMode parameter, that only affects vectors, such as GDI+ curves or lines.
Instead replace it with a half-pixel offset mode as 2. This will improve the quality of the upscaling.
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.
Also you can manage your own pixels by creating a pixel buffer, through varsetcapacity(size) and supplying that pointer to createbitmapfromscan0. The benefit would be to avoid repeated calls to rtlmovememory or LockBiys/UnlockBits. Although there’s so much going on i can’t tell if this would help.
So it seems that when you calculate the size of pBMTemp you should call createdibsection first, get the pBits, then overlay a bitmap by supplying pBits to CreateBitmapFromScan0 to save a call to lock/unlockbits.
I didn’t know you could save a DC and restore it to avoid an old bitmap. Thanks!
In your upscaling part, you don’t need a SmoothingMode parameter, that only affects vectors, such as GDI+ curves or lines.
Instead replace it with a half-pixel offset mode as 2. This will improve the quality of the upscaling.
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.
Also you can manage your own pixels by creating a pixel buffer, through varsetcapacity(size) and supplying that pointer to createbitmapfromscan0. The benefit would be to avoid repeated calls to rtlmovememory or LockBiys/UnlockBits. Although there’s so much going on i can’t tell if this would help.
So it seems that when you calculate the size of pBMTemp you should call createdibsection first, get the pBits, then overlay a bitmap by supplying pBits to CreateBitmapFromScan0 to save a call to lock/unlockbits.
I didn’t know you could save a DC and restore it to avoid an old bitmap. Thanks!
Re: Imagen() : A fade-in/fade-out animator for picture control
It should bepv007 wrote: ↑17 Jun 2021, 08:18Looks likeCant remove the picture.Code: Select all
guicontrol,, hPic
Code: Select all
guicontrol,, %hPic%
You need to call STM_SETIMAGE to remove he image.
Code: Select all
Imagen("Images\Imagen.png", "BackgroundTrans Fadein1000ms ahk_id" . hPic)
BackgroundTrans will be ignored when FadeIn is in effect.
If current image is smaller than the previous one, then previous image will be visible in transparent areas.
STM_SETIMAGE is done after blitting. The animation should/would reflect only what will be available in control's attached bitmap.
Code: Select all
#NoEnv
#Warn
#SingleInstance, Force
SetWorkingDir, %A_ScriptDir%
Gui, New, -Caption +Border
Gui, Color, 505050
Gui, Add, Picture, w400 h500 HwndhPic
Gui, Show
Sleep 500
Imagen("Images\Imagen.png", "Fadein1000ms ahk_id" . hPic)
Sleep 2000
hBitmap := DllCall("SendMessage", "Ptr",hPic, "Int",STM_SETIMAGE:=0x172, "Ptr",0, "Ptr",0, "Ptr")
DllCall("DeleteObject", "Ptr",hBitmap)
Return
Esc::ExitApp
Re: Imagen() : A fade-in/fade-out animator for picture control
@iseahound
Thanks for the tips.
I will test and apply suggestions made by you.
Yes. Mostly because of options parsing.SKAN, your code is impossibly hard to read and I’m surprised you manage to keep track of it without documentation.
Thanks for the tips.
I will test and apply suggestions made by you.
Re: Imagen() : A fade-in/fade-out animator for picture control
I have already demonstrated that in my VarV_RePNG(),
but no GDI bitmap is involved there.
I know how to share the same buffer between a GDI and GDI+ bitmap.
I am copying data because I want to kill the GDI bitmap before I process GDI+ bitmap.
If you know of a way to share the pixel buffer between GDI bitmap and GDI+ bitmap and yet kill the GDI bitmap without destroying pixel data, please share.
Re: Imagen() : A fade-in/fade-out animator for picture control
I think Windows manages the DIB itself for performance reasons, and so it seems unlikely, but I do not know for certain. Possible with CreateCompatibleBitmap and SetDIBits?
I actually learn a lot from reading your code, but this is a very large function, so I was wondering if you keep extra notes somewhere, because this is very big!
I actually learn a lot from reading your code, but this is a very large function, so I was wondering if you keep extra notes somewhere, because this is very big!
Re: Imagen() : A fade-in/fade-out animator for picture control
@SKAN is possible to fadeout? Just deleting instantly does not cause a 'nice' effect
Then it would fade out and stop at the value of 100 in transparency
Code: Select all
Imagen("imagen.png", "Fadein2000ms ahk_id" . BackGround)
Sleep 2000
Imagen("imagen.png", "FadeOut2000ms:100 ahk_id" . BackGround)
Re: Imagen() : A fade-in/fade-out animator for picture control
Try to wrap your mind around the following:pv007 wrote: ↑18 Jun 2021, 04:33Code: Select all
Imagen("imagen.png", "FadeOut2000ms:100 ahk_id" . BackGround)
Say If a pixel is already 50% transparent, you can't put a 49% transparent pixel over that unless you erase the previous pixel.
Any attempt to erase will cause flicker and hence Imagen() will write a solid background color over the pixel and then apply 49% transparent pixel.
As you ask, if Imagen() tried to fade from 100% - 0%, then the picture control needs to be erased 100 times.
I've explained it here: https://www.autohotkey.com/boards/viewtopic.php?p=380960#p380960
If you really need to do this, take a screen-shot bitmap of whatever is behind your picture control
and use Imagen() to fade-in that bitmap.
and then delete the control's picture with STM_SETIMAGE.
That is how things work in windows unless you use a layered window.
Return to “Scripts and Functions (v1)”
Who is online
Users browsing this forum: No registered users and 87 guests