Morning all,

I have the following code that gets a jpg image from sql which works fine.
What i would now like to do is save this image as a file on my pc in a temp folder that i can use in a report. i would like to change the name of this image to the sheltercode. can this be done.

below is the code that i use to get the image from the sql table and populate into a picture box on my form.

conn.Open()


            Using cmd As New SqlClient.SqlCommand("Select Imagedata From animalimage where sheltercode ='" & Me.lbshelter.Text & "'", conn)
                Using dr As SqlClient.SqlDataReader = cmd.ExecuteReader()
                    Using dt As New DataTable
                        dt.Load(dr)
                        If dt.Rows.Count = 0 Then Exit Sub
                        Dim row As DataRow = dt.Rows(0)
                        Using ms As New IO.MemoryStream(CType(row("Imagedata"), Byte()))
                            Dim img As Image = Image.FromStream(ms)
                            PictureBox1.Image = img
                        End Using
                    End Using
                End Using
            End Using
        End Using
        PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage

Try this:

After line 18 of your code provided to us, write these LOC:
Dim bmp as System.Drawing.Bitmap = new System.Drawing.Bitmap(PictureBox1.Image)
bmp.Save("FILENAME.jpg", System.Drawing.Imaging.ImageFormat.Jpeg)

this works a treat thank you very much.

Merry Christmas.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.