VB.NET School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 300,430 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,492 people online right now. Registration is fast and FREE... Join Now!




Get Image From file

 

Get Image From file

mansi sharma

3 Jul, 2009 - 05:04 AM
Post #1

New D.I.C Head
*

Joined: 19 Feb, 2009
Posts: 33



Thanked: 1 times
My Contributions
I want to get image from the file..I m able to do it....But mine code do not close the file,after getting the image,I want to close the file.Cz after getting the image,I want to delete that file.....on Deleteing error is dere file is user by another process...

CODE

Public Sub GetImagesContent(ByVal sFileName As String)
        Try
            Dim sExtension As String
            Dim img As System.Drawing.Image

            sExtension = System.IO.Path.GetExtension(sFileName)
            If Trim(sExtension) = ".bmp" Or _
                Trim(sExtension) = ".jpg" Or _
                Trim(sExtension) = ".jpeg" Or _
                Trim(sExtension) = ".gif" Or _
                Trim(sExtension) = ".png" Then
                img = Image.FromFile(sFileName)
                ImgThumbNailView.Images.Add(img)
           End if


IS Image.FromFile do not close the file????

Suppose I convert string to fileinfo object
[code]
dim a as fileinfo=new fileinfo(sFileName)
How to close the file,Can somebody tell me?

User is offlineProfile CardPM
+Quote Post


LoveIsNull

RE: Get Image From File

3 Jul, 2009 - 01:40 PM
Post #2

Disbanding my Ignorance
****

Joined: 10 Mar, 2009
Posts: 536



Thanked: 45 times
My Contributions
You need to use:
CODE
img.Dispose()


To release the resources you are using and also since this is a file, indicate it is no longer being used.
You should then be able to delete the image without error, assuming it isn't being used by another program.

As for you second question, you're not really "converting" a string to a System.IO.FileInfo object; you are essentially just creating an instance of a FileInfo object and passing it the required string parameter. This FileInfo object is in itself not a "file" per say, and so it does not need to be closed or disposed of. The FileInfo class does however contain methods allowing you to create, open, append, etc. to files which will actually return an instance of some kind of System.IO.Stream. You must call the Close() method on the stream to close it, and then the Dispose() method should be called automatically to release the resources it is using.

Edited to add more information.

This post has been edited by LoveIsNull: 3 Jul, 2009 - 01:54 PM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 12:35AM

Live VB.NET Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month