Solved

Resize image before loading to sqlserver

Posted on 2008-10-31
5
664 Views
Last Modified: 2012-05-05
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
Comment
Question by:dlavar
  • 2
  • 2
5 Comments
 
LVL 11

Assisted Solution

by:ladarling
ladarling earned 250 total points
ID: 22852173
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
 

Accepted Solution

by:
jsblindside earned 250 total points
ID: 22852171
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
 

Author Comment

by:dlavar
ID: 22852587
jsblindside, I couldn't access that image data source.  It kept displaying .....
Internet Explorer cannot display the webpage
0
 

Expert Comment

by:jsblindside
ID: 22852647
0
 

Author Comment

by:dlavar
ID: 22870817
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question