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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T16:44:28+00:00 2026-05-19T16:44:28+00:00

Can anyone shed any light on this issue please? ASP.NET 4.0 / C# The

  • 0

Can anyone shed any light on this issue please?

ASP.NET 4.0 / C#

The code:

Image image = Image.FromStream(Request.Files[0].InputStream);
var newWidth = 150;
var current = image.Width;
double scaleHeight = (150 / current);
if (scaleHeight == 0)
{
    scaleHeight = 0.2;
}
var newHeight = Convert.ToInt32(image.Height * scaleHeight);
var thumbnailBitmap = new Bitmap(newWidth, newHeight);
Graphics thumbnailGraph = Graphics.FromImage(thumbnailBitmap);

This code above always sets the scaleHeight as 0.2. Oddly the image.Width in the debugger is referencing the correct width of the image so logically 150 / x should give the decimal percentage 150 is of x, then I can workout a new height based on that percentage (height * result) – at least I think that’s the math! hehe.

Eg: 150/1024==0.1464. Then 768 * 0.1464 == 112 (int) – 14% of 768 is approx 112. This doesn’t work in the code – any ideas?

I’m clearly doing something stupidly wrong here, can anyone shed any light on this?

Sry for a daft question. Thanks for any help!

Chris.

  • 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-19T16:44:29+00:00Added an answer on May 19, 2026 at 4:44 pm

    This code above always sets the scaleHeight as 0.2

    Careful with your var’s. image.Width is an integer, so you are performing integer division here:

    (150 / current);
    

    If current is larger than 150 the result will always be 0. The act of assigning the result to a double does not mean that the result was not obtained using integer division. Try this:

    double scaleHeight = (150.0 / current);
    

    Of course, it really should be this:

    double newWidth = 150;
    var current = image.Width;
    double scaleHeight = (newWidth / current);
    

    As a side note, the ‘var’ keyword is great for reducing unnecessary verbosity in your code. However, I wouldn’t get into the habit of declaring everything as ‘var’. For one, it only serves to make your particular code snippet less clear. Secondly, you aren’t really saving any typing (ok, a few more letters to type ‘double’, but you need that!). My advice would be to use ‘var’ only when it makes your code easier to read/understand due to there being less unnecessary verbosity. For simple things like declaring an int it isn’t necessary and doesn’t add any value.

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

Sidebar

Related Questions

Hopefully someone can shed some light onto this issue for me. I have a
Can anyone shed any light on why I'm unable to click and play a
Can anyone tell me why this code would not be working? $('body').on('test', function() {
I have a really wierd issue that I'm hoping someone can shed some light
Can anyone shed some insight onto why the following happens? irb(main):001:0> r = '1'..'30'
Can anyone explain to me why this program: for(float i = -1; i <
Can anyone help - this is driving me mad. I am calling a mysql
Can anyone please tell/suggest me how can i store and retrieve comments multiple/different values
I'm having a strange issue here, i have this bit of code: <?php if
Since the documentation is a little spotty, I was wondering if anyone can shed

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.