Get Image From file
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...
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?
mansi sharma
Junior Poster in Training
75 posts since Apr 2008
Reputation Points: 17
Solved Threads: 0
__avd
Posting Genius (adatapost)
8,647 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
hi frnd, find the solution of mine code-
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Dim img As Image
Dim sFileName As String = "D:\Documents and Settings\Mansi\Desktop\Winter.jpg"
img = Image.FromFile(sFileName)
ImageList1.Images.Add(img)
PictureBox1.Image = ImageList1.Images.Item(0)
img.Dispose()
System.IO.File.Delete(sFileName)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
End Class
Can u provide me the code of urs,CZ i didnt know how to get image using from stream
mansi sharma
Junior Poster in Training
75 posts since Apr 2008
Reputation Points: 17
Solved Threads: 0
Use FileStream class:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Dim img As Image
Dim sFileName As String = "D:\Documents and Settings\Mansi\Desktop\Winter.jpg"
Dim fs as new System.IO.FileStream(sFileName,System.IO.FileMode.Open)
img = Image.FromStream(fs)
fs.close()
ImageList1.Images.Add(img)
PictureBox1.Image = ImageList1.Images.Item(0)
img.Dispose()
System.IO.File.Delete(sFileName)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
End Class
__avd
Posting Genius (adatapost)
8,647 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
mansi sharma
Junior Poster in Training
75 posts since Apr 2008
Reputation Points: 17
Solved Threads: 0