View previous topic :: View next topic |
Author |
Message |
AmyGrrl Cheater
Reputation: 0
Joined: 15 Dec 2016 Posts: 31
|
Posted: Sat Oct 20, 2018 7:58 pm Post subject: How can I make a image fade in and then fade out |
|
|
I've spent the last two hours trying to figure this out. I don't want to fade the whole form in. Just a specific image that I imported. About the only thing I can do with the imported image is to choose if I want it to be visible or not. I'm hoping this is something that is possible through lua. Thanks for any help given.
|
|
Back to top |
|
 |
ParkourPenguin I post too much
Reputation: 152
Joined: 06 Jul 2014 Posts: 4702
|
Posted: Sat Oct 20, 2018 9:08 pm Post subject: |
|
|
I don't know of any easy solution off the top of my head. Perhaps some library could.
You can manually paint the underlying canvas, but that could be difficult for a beginner.
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Sat Oct 20, 2018 9:57 pm Post subject: |
|
|
The picture control probably has an opacity property you can set in a timer to fade it in and out.
Edit: Apparently, Delphi doesn't inherit controls from something that would allow this like other languages. Go figure. :/
Well instead, you could load the image into a memory stream and later the data manually to edit the alpha of the image then set the picture box via the loadFromStream call.
_________________
- Retired. |
|
Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Sat Oct 20, 2018 10:41 pm Post subject: |
|
|
Here's the 'starting' bits of what I was referring to. You'd have to use an image format you are familiar with to edit the raw pixel data etc.
Code: |
local function getFileSize(file)
local s = 0;
local f = io.open(file, 'rb');
if (f ~= nil) then
s = f:seek('end');
f:close();
return s;
end
return s;
end
local function getFileData(file, size)
local f = io.open(file, 'rb');
if (f ~= nil) then
local data = f:read('*all');
local buff = { };
f:close();
for x = 1, size do
buff[x] = string.byte(data, x);
end
return buff;
end
return nil;
end
-- Load the image from disk..
local size = getFileSize('PATH_TO_IMAGE_HERE');
local data = getFileData('PATH_TO_IMAGE_HERE', size);
-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-- Edit the image data here..
-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-- Load the image into the stream..
local stream = createMemoryStream();
stream.write(data);
stream.Position = 0;
-- Load the image..
UDF1.CEImage1.Picture.loadFromStream(stream);
UDF1.CEImage1.Visible = true;
stream.destroy();
|
That'll allow you to edit the image data, load it into a stream, then load that stream into an image on the form.
_________________
- Retired. |
|
Back to top |
|
 |
AmyGrrl Cheater
Reputation: 0
Joined: 15 Dec 2016 Posts: 31
|
Posted: Sat Oct 20, 2018 11:36 pm Post subject: |
|
|
Kind of sucks there is no easy way to do this. Surprised nothing has been added to allow for this by now. A little disappointed.
What I did on my end to create a fade in. Was to use Gimp and edit the alpha level 7 different times. Using the values 30, 60, 90,120, 150, 180, 210. So I ended up with 8 different images that are around 80kb each. I then imported all the images and set them to invisible. Then created a threaded function to display them in order. With a slight delay between setting them invisible and visible. Works pretty well actually. But does increase the size a bit if you want to fade more than one image. But I only need on one image to fade in.
Tomorrow I will play around with your script and see if I can get it working. Being able to fade an image in through lua would be better because I would be able to create a more smooth transition.
|
|
Back to top |
|
 |
Dark Byte Site Admin
Reputation: 470
Joined: 09 May 2003 Posts: 25792 Location: The netherlands
|
Posted: Sun Oct 21, 2018 7:15 am Post subject: |
|
|
Have you looked into using wincontrol's setLayeredAttributes ?
put the image on a panel (which is a wincontrol descendant) and make that transparent (only works on win8 and later)
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
Back to top |
|
 |
Corroder Grandmaster Cheater Supreme
Reputation: 75
Joined: 10 Apr 2015 Posts: 1668
|
Posted: Tue Oct 23, 2018 6:13 am Post subject: |
|
|
This is another way to fade in part of form using form2 inside form1. When alpha value for form2 reach maximum it change to a panel with position same as form2.
Idea has come from MDI form like use in C++
Code: | function fadeinShow(form)
form.DoubleBuffered = true
form.AlphaBlend = true
form.AlphaBlendValue = 0
form.Visible = true
local timer = createTimer(form,false)
timer.Interval = 1
timer.OnTimer = function(t)
form.AlphaBlendValue = form.AlphaBlendValue + 2
if form.AlphaBlendValue>=250 then form.AlphaBlendValue = 255
form.AlphaBlend = false
t.Enabled = false
f.hide() -- or f.Destroy()
pnl = createPanel(form1)
pnl.top = form1.top + 10
pnl.left = form1.left + 10
pnl.width = form1.width - 20
pnl.height = 100
bg_image = createImage(pnl)
bg_image.picture.loadFromStream(findTableFile('teaser_1.jpg').Stream) -- add your own image to CE Table
bg_image.left = 0
bg_image.width = f.width
bg_image.height = f.height
bg_image.stretch = true
end
end
timer.Enabled = true
end
function closeAll()
f.destroy()
closeCE()
return caFree
end
form1 = createForm()
f = createForm()
f.top = form1.top + 40
f.left = form1.left + 10
f.width = form1.width - 20
f.height = 100
f.BorderStyle = 'bsNone'
bg_image = createImage(f)
bg_image.picture.loadFromStream(findTableFile('teaser_1.jpg').Stream) -- add your own image to CE Table
bg_image.left = 0
bg_image.width = f.width
bg_image.height = f.height
bg_image.stretch = true
fadeinShow(f)
--form1.show()
form1.onClose = closeAll
|
_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL |
|
Back to top |
|
 |
|