DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   VB.NET (http://www.daniweb.com/forums/forum58.html)
-   -   Get Image From file (http://www.daniweb.com/forums/thread201476.html)

mansi sharma Jul 3rd, 2009 10:00 am
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?

adatapost Jul 3rd, 2009 10:15 am
Re: Get Image From file
 
Use Image.FromStream

mansi sharma Jul 3rd, 2009 2:41 pm
Re: Get Image From file
 
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

adatapost Jul 3rd, 2009 10:55 pm
Re: Get Image From file
 
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

mansi sharma Jul 4th, 2009 3:20 pm
Re: Get Image From file
 
Thx


All times are GMT -4. The time now is 5:38 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC