943,711 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Marked Solved
  • Views: 6115
  • VB.NET RSS
Jul 3rd, 2009
0

Get Image From file

Expand Post »
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...

VB.NET Syntax (Toggle Plain Text)
  1. Public Sub GetImagesContent(ByVal sFileName As String)
  2. Try
  3. Dim sExtension As String
  4. Dim img As System.Drawing.Image
  5.  
  6. sExtension = System.IO.Path.GetExtension(sFileName)
  7. If Trim(sExtension) = ".bmp" Or _
  8. Trim(sExtension) = ".jpg" Or _
  9. Trim(sExtension) = ".jpeg" Or _
  10. Trim(sExtension) = ".gif" Or _
  11. Trim(sExtension) = ".png" Then
  12. img = Image.FromFile(sFileName)
  13. ImgThumbNailView.Images.Add(img)
  14. 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?
Similar Threads
Reputation Points: 17
Solved Threads: 0
Junior Poster in Training
mansi sharma is offline Offline
75 posts
since Apr 2008
Jul 3rd, 2009
0

Re: Get Image From file

Use Image.FromStream
Moderator
Reputation Points: 2136
Solved Threads: 1228
Posting Genius
adatapost is offline Offline
6,527 posts
since Oct 2008
Jul 3rd, 2009
0

Re: Get Image From file

hi frnd, find the solution of mine code-
VB.NET Syntax (Toggle Plain Text)
  1. Public Class Form1
  2.  
  3. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  4. Try
  5. Dim img As Image
  6. Dim sFileName As String = "D:\Documents and Settings\Mansi\Desktop\Winter.jpg"
  7. img = Image.FromFile(sFileName)
  8. ImageList1.Images.Add(img)
  9. PictureBox1.Image = ImageList1.Images.Item(0)
  10. img.Dispose()
  11. System.IO.File.Delete(sFileName)
  12. Catch ex As Exception
  13. MsgBox(ex.Message)
  14. End Try
  15. End Sub
  16.  
  17. End Class

Can u provide me the code of urs,CZ i didnt know how to get image using from stream
Last edited by mansi sharma; Jul 3rd, 2009 at 2:42 pm.
Reputation Points: 17
Solved Threads: 0
Junior Poster in Training
mansi sharma is offline Offline
75 posts
since Apr 2008
Jul 3rd, 2009
0

Re: Get Image From file

Use FileStream class:
VB.NET Syntax (Toggle Plain Text)
  1. Public Class Form1
  2.  
  3. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  4. Try
  5. Dim img As Image
  6. Dim sFileName As String = "D:\Documents and Settings\Mansi\Desktop\Winter.jpg"
  7. Dim fs as new System.IO.FileStream(sFileName,System.IO.FileMode.Open)
  8. img = Image.FromStream(fs)
  9. fs.close()
  10. ImageList1.Images.Add(img)
  11. PictureBox1.Image = ImageList1.Images.Item(0)
  12. img.Dispose()
  13. System.IO.File.Delete(sFileName)
  14. Catch ex As Exception
  15. MsgBox(ex.Message)
  16. End Try
  17. End Sub
  18. End Class
Moderator
Reputation Points: 2136
Solved Threads: 1228
Posting Genius
adatapost is offline Offline
6,527 posts
since Oct 2008
Jul 4th, 2009
0

Re: Get Image From file

Thx
Reputation Points: 17
Solved Threads: 0
Junior Poster in Training
mansi sharma is offline Offline
75 posts
since Apr 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: How to build the correct way of n-tier apps without service and remoting?
Next Thread in VB.NET Forum Timeline: how to upload a photo to a form in vb.net





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC