Advertisement

05.08.2008 at 08:22PM PDT, ID: 23388338
[x]
Attachment Details

Saving a cropped image

Asked by infintel789 in Microsoft Visual Basic.Net, Programming for ASP.NET

Tags: asp.net 2.0 vb

      I have code to upload and save a picture as a thumbnail.  The thumbnail code works great.  The problem is I'm trying to then crop the thumbnail to a square pixel of 55 by 55.    I'm using code that normally would be saving the image to a screen, but I'm saving the image as a file into a web directory.  The thumbnail saves as 55 x 55, but it is not being cropped.  It's just being squished to fit into  the 55 square.  Again, thumbnail code works great - I show some of it here just to show where I'm getting the image to work with to crop it.  Can someone look at my code starting at:
STARTING HERE FOR CROPPING THUMBNAIL IMAGE
and see if I'm either cropping wrong, or saving the cropped image wrong?   Thanks.


     code getting ready for thumbnail creation......

               Response.ContentType = "image/jpeg"
               'call the function to create the thumbnail
                thumb = Ettienne_Thumbnail(originalimg, height, width)
                'make the quality of thumbnail as good as possible
                Dim codecEncoder As ImageCodecInfo = GetEncoder("image/jpeg")
                Dim quality As Integer = 100
                Dim encodeParams As New EncoderParameters(1)
                Dim qualityParam As New EncoderParameter(Imaging.Encoder.Quality, quality)
                encodeParams.Param(0) = qualityParam
               
                thumbHeight = thumb.Height
                thumbWidth = thumb.Width

********  STARTING HERE FOR CROPPING THUMBNAIL IMAGE
                ' create a new bitmap that will be the end result for the cropped picture
                Dim bitthumb As New System.Drawing.Bitmap(55, 55, PixelFormat.Format24bppRgb)

                ' create a graphics object to work with
                Dim graphicthumb As Graphics = Graphics.FromImage(bitthumb)

                ' blank the image
                graphicthumb.Clear(Color.Blue)

                '# crop and resize!

                ' Set a unit of measurement as pixel
                ' could have used Inch, Point, etc
                Dim unit = GraphicsUnit.Pixel

                ' Draw image using the Pixel unit
                ' set above
                graphicthumb.DrawImage(thumb, New Rectangle(0, 0, 55, 55), New Rectangle(0, 0, thumbWidth, thumbHeight), unit)
               

                ' set the content type
                Response.ContentType = "image/jpeg"

                ' SAVE THE IMAGE USING THE ENCODE PARAMETERS
                bitthumb.Save(pathForThumb, codecEncoder, encodeParams)
                thumbHeight = bitthumb.Height
                thumbWidth = bitthumb.Width
                Start Free Trial
[+][-]05.09.2008 at 09:50AM PDT, ID: 21534630

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]05.09.2008 at 10:09AM PDT, ID: 21534785

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Microsoft Visual Basic.Net, Programming for ASP.NET
Tags: asp.net 2.0 vb
Sign Up Now!
Solution Provided By: TheLearnedOne
Participating Experts: 1
Solution Grade: B
 
 
[+][-]05.09.2008 at 11:34AM PDT, ID: 21535394

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628