FTP Slide Show

Horst

Member
Licensed User
Longtime User
Hello,

I am trying to realize a very simple FTP slide show by means of B4PPC6.5:

Sub App_Start
Form1.Show
ftp.New1
ftp.Open("ftp.softronics.ch","hlgast","hlg001")
ftp.SetCurrentDirectory("public")

For n = 1 To 3
fn = n & ".jpg"
ftp.GetFile(fn,AppPath & "\tmp.jpg") ' --> Error for n=2 !
Image1.Image = AppPath & "\tmp.jpg"
Image1.Refresh
Sleep (1000)
Image1.Dispose
'FileDel(AppPath & "\tmp.jpg") ' ---> impossible !
Next n
End Sub

The loop fails at n = 2 because "tmp.jpg" isn't released by the Image1.Image method.
Without showing the Image the loop is ending normally. The only possibility to access the tmp.jpg file (e.g. to delete it) is to cancel the program first.

Please help!
 

agraham

Expert
Licensed User
Longtime User
You are Disposing the Image control and not the Image itself which is probably not what you intend.

A .NET feature of Bitmaps loaded from image files is that the file is locked while the Bitmap exists. If you assign the next image before trying to delete the previous one it may work or you may have to explicitly Dispose/Release the Bitmap before deleting the file. Download my http://www.b4x.com/forum/additional-libraries/3171-imagelibex-library.html#post17721 and look in the help which has a discussion of Bitmap management. You might want to use a BitmapEx to load the image and then assign its Value property to your Image control Image property. This will allow you to explicitly release the Bitmap when you don't want it any more. Note that the technical section "Bitmap types and allocation" applies only to the device - I should have explicitly stated this although following the embedded link makes this clear.
 

Horst

Member
Licensed User
Longtime User
Hello Andrew,

many thanks for your quick answer and especially for your hint to your "Bitmap memory overview".
I have learned a lot from it!
Using the new version of your DLL with the Create and Release methods my little B4PCC exercise runs without any problems and so I can start a somewhat greater project.

Sub App_Start
Form1.Show
Sip(False)
ftp.New1
ftp.Open("ftp.softronics.ch","hlgast","hlg001")
ftp.SetCurrentDirectory("public")
bmpex.New2(220,175)
For n = 1 To 3
fn = n & ".jpg"
ftp.GetFile(fn,AppPath & "\tmp.jpg")
bmpex.Create1(AppPath & "\tmp.jpg")
Image1.Image = bmpex.Value
Image1.Refresh
Sleep (1000)
bmpex.Release
FileDel(AppPath & "\tmp.jpg")
Next n
End Sub

Thanks again.
Best regards

Horst
Germany
 

Horst

Member
Licensed User
Longtime User
Thank you very much, Erel!
Astonishing tricks!
Best regards

Horst
Germany
 

agraham

Expert
Licensed User
Longtime User
B4X:
bmpex.New2(220,175)
To aid understanding I will comment that, pedantically, New4 would be a better choice. New2 creates a bitmap of the given size and then Create1 immediately disposes it and creates another. When a new bitmap is created by one of the Create methods or assigned to the Value property the size of the existing bitmap, if any, has no bearing upon the size of the new one. The size is a property of the underlying bitmap, a BitmapEx itself holds no size information
 
Top