-1

In some cases ,like you want to save image related to your content as cover image.

Original image is so bigger and it is not good idea to show original one to user if user does not want it.If user wants he can click and see large one .

So in this cases better to save images in different sizes.So you need to re-size it.So how we have to re-size and save it?

RASKOLNIKOV
  • 732
  • 2
  • 9
  • 20

1 Answers1

1

So lets start :

First of all think that you have one file upload control in form.

Like this one

<asp:FileUpload runat="server" ID="uploadImage"></asp:FileUpload>

When save button clicked you want to call one function and re-size and save upload the image.

This is our function :

public void SaveResizedImage()
        {
            // if no file do nothing
            if (!uploadImage.HasFile) return;
            var file = uploadImage.PostedFile;
            var originalImage = Image.FromStream(file.InputStream);

            // enter width and height
            var resizedImage = new Bitmap(width, heigth);
            using (var g = Graphics.FromImage(result))
            g.DrawImage(bitmap, 0, 0, width, heigth);
            // it is better to save files with unique 
            //name rather saving  them with originals  
            resizedImage.Save(FolderPath + uploadedImage.FileName);

        }

Bingo!

For creating unique names for files please look to this title

Community
  • 1
  • 1
RASKOLNIKOV
  • 732
  • 2
  • 9
  • 20