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 7954799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:32:27+00:00 2026-06-04T03:32:27+00:00

I have a method as shown below to save image as jpeg. I want

  • 0

I have a method as shown below to save image as jpeg.
I want to save all the pictures with the same height and width without it getting distorted.

How can I do that?
Please help

public void SaveFileOnDisk(MemoryStream ms, string FileName)
{
    try
    {
        string appPath = HttpContext.Current.Request.ApplicationPath;
        string physicalPath = HttpContext.Current.Request.MapPath(appPath);
        string strpath = physicalPath + "\\Images";
        string WorkingDirectory = strpath;


        System.Drawing.Image imgSave = System.Drawing.Image.FromStream(ms);
        Bitmap bmSave = new Bitmap(imgSave);
        Bitmap bmTemp = new Bitmap(bmSave);

        Graphics grSave = Graphics.FromImage(bmTemp);
        grSave.DrawImage(imgSave, 0, 0, imgSave.Width, imgSave.Height);

        bmTemp.Save(WorkingDirectory + "\\" + FileName + ".jpg");


        imgSave.Dispose();
        bmSave.Dispose();
        bmTemp.Dispose();
        grSave.Dispose();
    }
    catch (Exception ex)
    {
        //lblMsg.Text = "Please try again later.";
    }

}
  • 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-06-04T03:32:29+00:00Added an answer on June 4, 2026 at 3:32 am

    Resize the Image and Save it

    Private void ResizeImage(Image img, double maxWidth, double maxHeight)
    {
        double srcWidth = img.Source.Width;
        double srcHeight = img.Source.Height;
    
        double resizeWidth = srcWidth;
        double resizeHeight = srcHeight;
    
        double aspect = resizeWidth / resizeHeight;
    
        if (resizeWidth > maxWidth)
        {
            resizeWidth = maxWidth;
            resizeHeight = resizeWidth / aspect;
        }
        if (resizeHeight > maxHeight)
        {
            aspect = resizeWidth / resizeHeight;
            resizeHeight = maxHeight;
            resizeWidth = resizeHeight * aspect;
        }
    
        img.Width = resizeWidth;
        img.Height = resizeHeight;
    }
    

    You could use this code to Resize the image to the required Dimention Before saving it

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a method (shown below). The project is compiled using ARC, but
I have re-factored one of the method as shown below ,personally I think it
I have a method as shown below... public bool MakeRequest(string[] args) { try {
I'm getting an exception randomly with the Send method shown below. The exception I'm
i want show tooltip with image tag and i have written code like below
I have the method shown below which is generating a CA1822 Code Analysis warning.
I have a method which insert a record into a table as shown below:
i have a problem is shown below; groovy.lang.MissingMethodException: No signature of method: static org.springframework.security.oauth.User.withTransaction()
I have created a Method shown below, public BOEod CheckCommandStatus(BOEod pBo, IList<string> pProperties) {
I have q method that shown at below: void MainWindow::slotResults( const QList<QSqlRecord>& records )

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.