filedel after use

Discussion in 'Questions (Windows Mobile)' started by derez, Feb 3, 2009.

  1. derez

    derez Expert Licensed User

    Hi
    How can I delete a file after using it by drawimage ?
    The following example does not run because test1.jpg is in use, even though the form is already drawn with test2.jpg :confused:

    Code:
    Sub App_Start
       Form1.Show
       form1.DrawImage(
    "test1.jpg",0,0)
       form1.DrawImage(
    "test2.jpg",0,0)
       FileDel(
    "test1.jpg")
    End Sub
    I'm sure it must be a simple answer but I can't find it...
    Thanks
     
  2. Cableguy

    Cableguy Expert Licensed User

    Yes...simple...you can't...
    Any image file used by a b4p app stays locked by b4p, even after fileclose...
    This behaviour only happens with image files...
    ie:
    set an image control file in designtime and run your app...
    from that firstrun, the image file will no longer be available to be overwritten, unless you stop the b4p ide...
    This is one of the most awaited features to be yet acomplished...the image files unlocking...
     
  3. derez

    derez Expert Licensed User

    Thank you Paulo.

    Lets see if you can help me with a workaround to this.
    The application in mind is sending the form image to another device using network, in a continuous way.

    It works using saveimage from imagelibEx.dll and then sending the file, and in the recieving device by form.drawimage. But to save the file that is recieved I need to delete the file that was recievd before, and it is in use !!!
    alternatively I can save the recieved file in a different name each time but then the memory will explode from all these files that stay locked :(

    If there a way to recieve the stream and create an image directly, not by using a file in the middle, then the problem is solved.

    Agraham
    In ImagelibEx there is SaveImageToStream but there is no SaveStreamToImage ! can you add it ?

    Any suggestion ?
     
    Last edited: Feb 4, 2009
  4. agraham

    agraham Expert Licensed User

    I could but I think you will run into the same locking problem with a stream as with a file. This locking of the file or stream is a .NET Bitmap object "feature" not a Basic4ppc bug. The lock lasts for the life of the Bitmap. If you Dispose the Bitmap and have no other references to it, that is it is not assigned to an Image or Form, then the file should become free again. You can then recreate the Bitmap with AddObject.

    There is a bug in Basic4ppc that means you should not call New more than once once on any library object that uses native resources, like a Bitmap or BitmapEx. See this thread http://www.basic4ppc.com/forum/questions-help-needed/3655-image-zoom-memory-problem.html
     
  5. derez

    derez Expert Licensed User

    Agraham
    your suggestion will do if you tell me how to dispose the bitmap which is displayed on the form, since I want to display a new one and even get rid of the image file.
     
  6. agraham

    agraham Expert Licensed User

    Have a small, say 1 x 1 Bitmap that you keep as a placeholder. Assign it to Form.Image which means that the original Bitmap is no now longer referenced anywhere. Dispose that original Bitmap and start again.
     
  7. derez

    derez Expert Licensed User

    [If you look at the first post you can see that even if I draw another bitmap I can't delete the first image file, it is locked until the program ends.
    And again - how do you dispose a bitmap (other than drawing over it) ?
    The following code has the same problem:

    Code:
    Sub App_Start
       Form1.Show
       imagelist1.Add(
    "test1.jpg")
       form1.image = imagelist1.Item(
    0)
       imagelist1.Add(
    "test2.jpg")
       form1.image = imagelist1.Item(
    1)
                 imagelist1.RemoveAt(
    0)
       FileDel(
    "test1.jpg")
    End Sub
     
    Last edited: Feb 4, 2009
  8. Erel

    Erel Administrator Staff Member Licensed User

  9. derez

    derez Expert Licensed User

    Thank you Erel, I think that this is the solution :)
    with the code below, if an imagefile named test[n].jpg is created by another process, the sub will display it on the form and delete the file.

    Code:
    Sub Globals
    n = 
    0
    End Sub

    Sub App_Start
    form1.Show
    End Sub

    Sub Button1_Click
    n = n+
    1
    AddObject(
    "bitmap1","Bitmap")
    bitmap1.New1(AppPath & 
    "\test" & n & ".jpg")
    image1.Image = bitmap1.Value
    form1.Image = image1.Image
    bitmap1.Dispose
    FileDel(
    "test" & n & ".jpg")
    End Sub
     
    Last edited: Feb 4, 2009
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice