Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 671
  • Last Modified:

Resize image before loading to sqlserver

On my application, I have programmed to where the user can load images and display them using crystal reports 10. Well I have no problem loading images.  but if they happen to be too big, crystal reports will not display them.  So I need help writing code to resize the image before loading it to the server.  Here is the code I have thus far.
Dim fileName As String
        Dim fileType As String
        Dim namePosition As Int16
        Dim stream As IO.Stream
 
        stream = file1.PostedFile.InputStream
        Dim uploadedFile(stream.Length) As Byte
        stream.Read(uploadedFile, 0, stream.Length)
 
        namePosition = file1.PostedFile.FileName.LastIndexOf("\") + 1
        fileName = file1.PostedFile.FileName.Substring(namePosition)
        fileType = file1.PostedFile.ContentType
 
 
                Try
            Session("Casenumber") = strcasenumber
            dtreportdate = Now.Date
            strdescription = txtdescription.Text
            strDSFM = ddldsfm2.SelectedItem.Value
 
            connFF.Open()
            With cmdImages.Parameters
                .Add("@casenumber", strcasenumber)
                .Add("@reportdate", dtreportdate)
                .Add("@description", strdescription)
                .Add("@DSFM", strDSFM)
                .Add("@pic", uploadedFile)
            End With
 
            cmdImages.ExecuteNonQuery()
            connFF.Close()
            Response.Write("<script language= javascript>alert(""Image have been saved for casenumber " + strcasenumber + "!"");</script>")
            btnPrintImage.Visible = True
            SetInitialFocus(btnPrintImage)
 
        Catch er As Exception
            LogError(er.ToString, "Submit-ReportNotes.aspx")
            Exit Try
        Finally
            connFF.Close()
        End Try
    End Sub

Open in new window

0
dlavar
Asked:
dlavar
  • 2
  • 2
2 Solutions
 
ladarlingCommented:
The concept of the operation is to cast the stream to a bitmap, figure out its current dimensions, and then re-draw the bitmap (to another bitmap object) using your corrected dimensions.
Here is a link to some code that does what you need:
http://www.vb-helper.com/howto_net_image_resize.html

Note that the 'scale factor' in this example will control the relative dimension increase/decrease. If you have a fixed maximum size, you could omit  that and hard code it, of course.
Also, Since your image is already in a stream object, you can use the stream argument overload of the Bitmap object to instantiate your 'pre-resize' image. So, something like:

Dim img As New Bitmap(stream)
 
0
 
jsblindsideCommented:
We're working on a project which involves a database that references a bundle of jpgs (a few thousand, give or take).

Crystal Reports has been working OK, with a few tweaks...

We can make a report display the images easily (the value in the database is 'X:\Images\Image123.jpg'). The issue we were having was resizing them - we could set it to 200x200 or whatever, but the issue was when one image was portrait and the next landscape - CR just didn't seem able to handle that.

To work around this, we created a simple PHP script which resizes the image to the correct proportions, with whitespace added as necessary. Messy, but effective. We now have the image data source as
http://someServer/getImage.php?imag...=200&w=250.

This works really well, and has saved us a lot of headaches!

"I copied this from a forum where someone was having similar problems.  Try using that source and it should automatically resize the images." Thank you
0
 
dlavarAuthor Commented:
jsblindside, I couldn't access that image data source.  It kept displaying .....
Internet Explorer cannot display the webpage
0
 
jsblindsideCommented:
0
 
dlavarAuthor Commented:
ladarling I'm sorry but I'm still at a lost because I'm having a problem declaring the stream as bitmap.  I keep getting all types of blue line errors.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now