• 0

C# - Converting floats to pixels


Question

2 answers to this question

Recommended Posts

  • 0

This should work. If I understand your question correctly, you're trying to find the scaling percentage for any width image so that the final width is 204 px. Try this equation:

204 = width * scale%

so:

scale% = 204/width

And the scale% is the float you want. Also, make sure you're not dividing integers or else you won't get any decimal places. So, just make sure to convert the width to a float: Convert.ToFloat(width) before dividing 204.0 by it. Hope that helps.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Support? You mean the support that microsoft's phone lines now just direct you to their website to look for a non-existent solution to Office problems (like all the ones they've been introducing to Outlook Classic), and hangs up on you? Don't think anyone would miss such mediocre "support"...
    • Unbelievably good deal sees this AMD Ryzen Windows 11 Lenovo laptop selling for just $266 by Sayan Sen While desktops are generally more powerful, laptops can be quite handy as they offer portability while also providing about 70-80% of the performance of a similar-priced desktop. If you are in the market shopping for one, then Lenovo is offering one with AMD's Ryzen 8-core APU at a low price of just $266 (purchase link down below). The discounted model we are specifically talking about here is the Lenovo IdeaPad 3 15ALC6., It is a 15.6-inch notebook powered by the AMD Ryzen 5700U APU, built on an 8-core 16-thread Zen 2 CPU and Vega 8 integrated graphics. The device has plenty of memory too, as it packs 12 GB of DDR4-3200 memory where 4 Gigs are soldered while the remaining 8 GB SODIMM is upgradable. Since the memory configuration is asymmetrical, the laptop likely supports flex mode and thus 8 out of 12 GB should be running in dual channel mode while the remaining 4 is in single channel mode. The laptop has a 512 GB M.2 2242 SSD for storage. Get it at the link below: Lenovo 2023 Ideapad 15.6 Inch FHD Touchscreen, 12GB RAM, 512GB SSD, Wi-Fi 6, Bluetooth 5, Windows 11 Home: $265.70 (Shipped and Sold by Amazon US) You may notice the poor reviews for this laptop on Amazon but that is apparently due to a possibly fraudulent seller. This Amazon deal is US-specific and not available in other regions unless specified. If you don't like it or want to look at more options, check out the Amazon US deals page here. Get Prime (SNAP), Prime Video, Audible Plus or Kindle / Music Unlimited. Free for 30 days. As an Amazon Associate, we earn from qualifying purchases.
    • This is obviously the most buggy web browser.
    • Uhm, why the preferential treatment for 1Password instead of simply providing an API for all password managers to plug into? I ditched 1Password for Enpass soon as Agilebits began forcing their cloud sh*t into 1Password. Have no reason to switch from the 100% locally-hosted Enpass...
  • Recent Achievements

    • Week One Done
      emptyother earned a badge
      Week One Done
    • Week One Done
      DarkWun earned a badge
      Week One Done
    • Very Popular
      valkyr09 earned a badge
      Very Popular
    • Week One Done
      suprememobiles earned a badge
      Week One Done
    • Week One Done
      Marites earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      566
    2. 2
      +FloatingFatMan
      178
    3. 3
      ATLien_0
      177
    4. 4
      Xenon
      119
    5. 5
      Som
      112
  • Tell a friend

    Love Neowin? Tell a friend!