Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 251547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:36:13+00:00 2026-05-11T21:36:13+00:00

A user will be able to upload an image. If the image is greater

  • 0

A user will be able to upload an image. If the image is greater than a set size I want to downsize it to that size. Obviously it doesn’t have to match exactly due to ratios, the width would be the key size so the height would be variable.

If the image is smaller than the set size I would like to create a new image to the set size with a background of a defined colour and then centre the uploaded image into it therefore the result is the original with paddded colour.

Any code examples or links greatly appreciated

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T21:36:13+00:00Added an answer on May 11, 2026 at 9:36 pm

    Here’s a snippet of code I quickly knocked up for resizing it based on the width. I’m sure you could figure out how to add a background color to the Bitmap. It’s not complete code but just an idea of how to do things.

    public static void ResizeLogo(string originalFilename, string resizeFilename)
    {
        Image imgOriginal = Image.FromFile(originalFilename);
    
        //pass in whatever value you want for the width (180)
        Image imgActual = ScaleBySize(imgOriginal, 180);
        imgActual.Save(resizeFilename);
        imgActual.Dispose();
    }
    
    public static Image ScaleBySize(Image imgPhoto, int size)
    {
        int logoSize = size;
    
        float sourceWidth = imgPhoto.Width;
        float sourceHeight = imgPhoto.Height;
        float destHeight = 0;
        float destWidth = 0;
        int sourceX = 0;
        int sourceY = 0;
        int destX = 0;
        int destY = 0;
    
        // Resize Image to have the height = logoSize/2 or width = logoSize.
        // Height is greater than width, set Height = logoSize and resize width accordingly
        if (sourceWidth > (2 * sourceHeight))
        {
            destWidth = logoSize;
            destHeight = (float)(sourceHeight * logoSize / sourceWidth);
        }
        else
        {
            int h = logoSize / 2;
            destHeight = h;
            destWidth = (float)(sourceWidth * h / sourceHeight);
        }
        // Width is greater than height, set Width = logoSize and resize height accordingly
    
        Bitmap bmPhoto = new Bitmap((int)destWidth, (int)destHeight, 
                                    PixelFormat.Format32bppPArgb);
        bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);
    
        Graphics grPhoto = Graphics.FromImage(bmPhoto);
        grPhoto.InterpolationMode = InterpolationMode.HighQualityBicubic;
    
        grPhoto.DrawImage(imgPhoto,
            new Rectangle(destX, destY, (int)destWidth, (int)destHeight),
            new Rectangle(sourceX, sourceY, (int)sourceWidth, (int)sourceHeight),
            GraphicsUnit.Pixel);
    
        grPhoto.Dispose();
    
        return bmPhoto;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form (code below) that allows a user to upload an image
I want to create a function that after an image upload, will allow a
According to current requirement,user will upload files with large size,which he may like to
I have an aspx page,where the user will enter a valid image url(ex :
I have a textbox where user will enter the url of the image :
I'm looking to have users upload an image and then it will be cropped
I want a user to be able to upload a word document and my
I have an app where I want users to be able to upload a
Quick question: We want to be able to store a user avatar image for
The user will be able to search for some document in the local machine

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.