Good quality image to SQL server...

lidds

Well-known member
Joined
Oct 19, 2004
Messages
122
Programming Experience
Beginner
I have an application that performs a screen capture and displays it in a pictureBox contol. This works fine and the quality of the image displayed in the pictureBox is excellent (same quality as on screen), however when I save it to an SQL database and then reload it, the quality is greatly reduced.

I think this is something to do with the way that I am saving the image to SQL?

The code I am using is below:

VB.NET:
'Read image into byte 
                ' save image to stream... 
                Dim clsStream1 As New System.IO.MemoryStream 
                Me.picPreview.Image.Save(clsStream1, System.Drawing.Imaging.ImageFormat.Jpeg) 

                ' read bytes from stream... 
                Dim emptyByte As Byte = Nothing 
                Dim b As Byte() = DirectCast(Array.CreateInstance(GetType(Byte), clsStream1.Length), Byte()) 
                clsStream1.Position = 0 
                clsStream1.Read(b, 0, b.Length) 
                clsStream1.Close()

I then load the byte array into SQL. Is there a better way that I can do this and keep the image quality as good as displayed in the pictureBox?

Thanks in advance

Simon
 
You're saving the image as Jpeg, which means compressed and loss of detail. Saving as bitmap (bmp) doesn't loose anything but takes lots of space. Png image format may take much less space and still have good quality. There's also the option of changing the default Jpeg compression, which I think is 70%, to higher - Paint.Net uses 95% as default for Jpeg for example.
 
Back
Top