[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Resizing photos dynamically in ASP.NET and C#

Posted on 2008-02-08
4
Medium Priority
?
1,410 Views
Last Modified: 2013-11-26
I am looking for some code to get me started in resizing photos.  Users uploaded photos of any size, with just a restriction of 3 mb.  The height and width can be of any size.  So when the users click on the thumbnail of the image, their original photo is displayed and it usually is of a size that is bigger than the web browser and the users have to scroll horizontally and vertically to see the photo.  What I'm looking to do is resize/recrop the the photo so that it is more manageable to view.  I'd like to be able to open a popup web browser at a certain size, say 600 pixels, and have that as the base for the photo to be recropped around.  Obviously the photo can't be recropped to 600x600 or it would be distorted one way or another.  Any help would be appreciated.
Thanks in advance....
0
Comment
Question by:URSIMS
3 Comments
 
LVL 13

Accepted Solution

by:
Velio earned 1000 total points
ID: 20853725
this function is one way of scaling an image.

should be fairly easy to calculate the scale you should be scaling at to get to a desired target width/height...

scale = targetWidth / originalWidth or targetHeight / originalHeight
        private Image ScaleImage(Image image, double scale)
        {
            Image result = new Bitmap(image, new Size((int)(image.Size.Width * scale), (int)(image.Size.Height * scale)));
            return result;
        }

Open in new window

0
 
LVL 8

Assisted Solution

by:digital_thoughts
digital_thoughts earned 1000 total points
ID: 20853749
There are a number of articles on how to accomplish what you are needing, here are just a few:

http://www.codeproject.com/KB/GDI-plus/imageresize.aspx

http://blog.paranoidferret.com/?p=11
0
 
LVL 1

Expert Comment

by:Computer101
ID: 21250251
Forced accept.

Computer101
EE Admin
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
This video tutorial shows you the steps to go through to set up what I believe to be the best email app on the android platform to read Exchange mail.  Get the app on your phone: The first step is to make sure you have the Samsung Email app on your …
Suggested Courses

607 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