Solved

Resize image before loading to sqlserver

Posted on 2008-10-31
5
662 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

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…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

770 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