Solved

Resize image before loading to sqlserver

Posted on 2008-10-31
5
660 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
Comment Utility
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
Comment Utility
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
Comment Utility
jsblindside, I couldn't access that image data source.  It kept displaying .....
Internet Explorer cannot display the webpage
0
 

Expert Comment

by:jsblindside
Comment Utility
0
 

Author Comment

by:dlavar
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

763 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now