Click here to Skip to main content
15,911,030 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am getting an error on saving images from picture box.
<br />
Public Class Form1<br />
    Dim open As OpenFileDialog<br />
    Dim i As String<br />
    Dim img As Image = Nothing<br />
    Dim pic As String<br />
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<br />
    End Sub<br />
<br />
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click<br />
        open = New OpenFileDialog<br />
        open.Filter = "Image Files(*.jpg;*.jpeg;*.gif;*.bmp;*.png;*.tif)|*.jpg;*.gif;*.bmp;*.tif"<br />
        open.ShowDialog()<br />
        pic = open.FileName<br />
        Try<br />
            Dim fs As New System.IO.FileStream(pic, IO.FileMode.Open, IO.FileAccess.Read)<br />
            img = Image.FromStream(fs)<br />
            fs.Close()<br />
            fs.Dispose()<br />
            emppic.Image = img<br />
        Catch ex As Exception<br />
            img = Nothing<br />
        End Try<br />
    End Sub<br />
<br />
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click<br />
        Dim img6 As Image<br />
        img6 = emppic.Image<br />
        Try<br />
            emppic.Image.Save("C:\C-tek\Images\Temp\1.jpg", System.Drawing.Imaging.ImageFormat.Jpeg)<br />
        Catch ex As Exception<br />
            MsgBox("File  Saving Error." + ex.ToString)<br />
        End Try<br />
    End Sub<br />
End Class

please hlp me.thnk in advance
Posted
Comments
sp_suresh 23-Oct-13 1:45am    
what is error and on which line?...
Member 9377677 23-Oct-13 1:51am    
line 30 emppic.image.save

1 solution

Look at the documentation: Image.FromStream[^]
The important bit is:
"You must keep the stream open for the lifetime of the Image."

You don't. Thus your problem!
 
Share this answer
 
Comments
Member 9377677 23-Oct-13 1:54am    
but I have to delete the file after its uploaded to stream.
Member 9377677 23-Oct-13 1:58am    
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
open = New OpenFileDialog
open.Filter = "Image Files(*.jpg;*.jpeg;*.gif;*.bmp;*.png;*.tif)|*.jpg;*.gif;*.bmp;*.tif"
open.ShowDialog()
pic = open.FileName
Try
Dim fs As New System.IO.FileStream(pic, IO.FileMode.Open, IO.FileAccess.Read)
img = Image.FromStream(fs)
fs.Close()
fs.Dispose()
My.Computer.FileSystem.DeleteFile(pic)
emppic.Image = img
Catch ex As Exception
img = Nothing
End Try
End Sub
Member 9377677 23-Oct-13 2:26am    
please provide me solution. thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900