Save/Retrieve Image from Database (quality issue) 
Author Message
 Save/Retrieve Image from Database (quality issue)

Here's the scenario:

1) I load an image into memory using the Drawing.Image class using the
following code:
Dim Image As System.Drawing.Image
Image = System.Drawing.Image.FromFile("D:\PROJECTS\Test Images\Test4.JPG")

2) In preparation to save the image into a SQL Server DB, I convert the
image into a Byte array using the following code:
Dim ms As New System.IO.MemoryStream()
Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)
Dim b(ms.Length - 1) As Byte
ms.Position = 0
ms.Read(b, 0, ms.Length)

3) I save the image into the database using the following code:
Dim conn As New SqlClient.SqlConnection("Data Source=TestServer;Initial
  Catalog=TestDB;User ID=sa;Password=")
Dim SQLCommand As New SqlClient.SqlCommand("INSERT INTO Images (ImageBinary)

          With SQLCommand

                SqlDbType.Image)).Value = b
          End With
      Catch x As Exception
      End Try

4) I retrieve the image from the database using the following code:
Dim da As New SqlClient.SqlDataAdapter("Select * From Images", conn)
Dim ds As New DataSet()
Dim dt As DataTable

da.Fill(ds, "Images")
dt = ds.Tables("Images")

Dim newImage As System.Drawing.Image
Dim b2(dt.Rows(0).Item("ImageBinary").length) As Byte
b2 = dt.Rows(0).Item("ImageBinary")
newImage = Image.FromStream(New System.IO.MemoryStream(b2))

So, the question -- when I retrieve the image from the database the quality
of the image has been reduced significantly.  My ultimate goal is to put
this image on a report (using Crystal for VS.NET) and print out the report.
However, when I put the image on the report the quality of the image is too
poor to print out.

I figure I missing something somewhere or am not setting a property
correctly.  Any thoughts?

(Please note the code above is simply test code and I realize it may not be
optimized -- my main concern is the image quality issue that I'm
experiencing at this point in time.)

Thanks in advance for any help you might be able to provide.

TK Herman

Sat, 05 Mar 2005 22:36:11 GMT  
 Save/Retrieve Image from Database (quality issue)
Hi, TK

Thanks for the prompt response.

When I talked this over with the GDI+ guys they speculated that one of the
pieces was changing the compression on the jpg.  Crystal might be doing
that, or it might be where they do the conversion to a bitmap to print it.  
If you convert to screen resolution instead of printer resolution, you get
jaggies and other unappetizing effects.  It would also be bad if they
assumed 300dpi and you are doing 1200.  No way to tell for sure until we
check it out.  I'm at home RASed in to clean up any loose ends, so my
resources are limited.  For Crystal.Net issues you may be better off
posting on CrystalDecisions' web site:

Posting there will give you the best visibility to the people who are most
familiar with the technology.

Please post back with the results.  If they don't have a solution, I will
ping some people here and see what we can find out.


John Eikanger
Microsoft Visual Basic Developer Support

This posting is provided AS IS with no warranties, and confers no rights.
(c) 2002 Microsoft Corporation.  All rights reserved.

| Subject: Re: Save/Retrieve Image from Database (quality issue)
| Date: Tue, 17 Sep 2002 18:34:35 -0500
| Lines: 148
| X-Tomcat-NG: microsoft.public.dotnet.languages.vb
| Hi John -
| Thanks for the reply!  Ok, I did your test -- saved the image to a file
| after it came back from the database.  (Don't know why I didn't think of
| that test myself but oh well...)  So, by just looking at the images in my
| favorite photo viewer (Windows Picture View of course) :) it's my opinion
| that I can't tell the difference.  On thing that is interesting is that
| file size went from 14,231 bytes (original image) to 14,503 (saved image
| it came out of the DB).
| Ok, so now it appears that my problem actually exists on the Crystal
| which I'm trying to use print the image.  (I'm using Cryrstal Reports for
| VS.NET.)  Ultimately when I get this working what will happen is the user
| will select eight pictures and save them into a database.  The user will
| them have the option to print out a page with all eight images.  (All
| will be .jpg's and landscape in format.)
| With that information -- any thoughts why the quality of the image sitting
| on the Crystal Report is so poor?  By poor I mean granularity -- the
| are fine but the detail is terrible.
| Thanks again for the post!
| TK

Sun, 06 Mar 2005 09:20:11 GMT  
 [ 2 post ] 

 Relevant Pages 

1. Retrieve Bitmap of preview image - Summary Info - Save Preview Image

2. Save image in Sql Server and retrieve image from sqlserver to vb

3. Picture or Image ctrl - image quality

4. Saving and retrieving image control picture property in MSSQL7

5. saving and retrieving image type data

6. Miniature/ preview scale quality issue

7. Saving/Retrieving a Winword object in a Access database

8. Retrieving images from an Access database?

9. Retrieving Images from a Database

10. retrieve image from database

11. Retrieving and displaying images stored as OLE in access database

12. How to retrieve image field from database


Powered by phpBB® Forum Software