Solved

Resize image before loading to sqlserver

Posted on 2008-10-31
5
666 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

710 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