Get Image From file

Please support our VB.NET advertiser: $4.95 a Month - ASP.NET Web Hosting – Click Here!
Thread Solved
Reply

Join Date: Apr 2008
Posts: 75
Reputation: mansi sharma is an unknown quantity at this point 
Solved Threads: 0
mansi sharma mansi sharma is offline Offline
Junior Poster in Training

Get Image From file

 
0
  #1
Jul 3rd, 2009
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...

  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?
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,421
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 433
adatapost's Avatar
adatapost adatapost is offline Offline
Nearly a Posting Maven

Re: Get Image From file

 
0
  #2
Jul 3rd, 2009
Use Image.FromStream
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 75
Reputation: mansi sharma is an unknown quantity at this point 
Solved Threads: 0
mansi sharma mansi sharma is offline Offline
Junior Poster in Training

Re: Get Image From file

 
0
  #3
Jul 3rd, 2009
hi frnd, find the solution of mine code-
  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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,421
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 433
adatapost's Avatar
adatapost adatapost is offline Offline
Nearly a Posting Maven

Re: Get Image From file

 
0
  #4
Jul 3rd, 2009
Use FileStream class:
  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
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 75
Reputation: mansi sharma is an unknown quantity at this point 
Solved Threads: 0
mansi sharma mansi sharma is offline Offline
Junior Poster in Training

Re: Get Image From file

 
0
  #5
Jul 4th, 2009
Thx
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC