• 0

image quality lost on resize asp.net


Question

I'm building an app where the user can upload an image and the app will resize the image to the appropriate size. When this happens, once the image gets resized, the image quality degrates and looks crappy... Can anybody help me out?

MY CODE

'comes from a popup box where user selects the file

Dim img As System.Drawing.Image = System.Drawing.Image.FromStream(.InputStream)

Dim imageFormat = img.RawFormat

Dim thumbSize As New Size

thumbSize = NewthumbSize(img.Width, img.Height)

Dim imgOutput As New Bitmap(img, thumbSize.Width, thumbSize.Height)

imgOutput.Save(Path.Combine(Server.MapPath("../photo/imagesileName), imageFormat)

'this function finds the correct multiplier to resize the image

Function NewthumbSize(ByVal currentwidth, ByVal currentheight)

Dim tempMultiplier As Double

'check to see if image is portrait or landscape

If currentheight > currentwidth Then

'check to see if image height is smaller then what we want

If currentheight < 400 Then

tempMultiplier = 1 'don't change the image size

Else

tempMultiplier = 400 / currentheight

End If

Else

'check if width of image is smaller then what we want

If currentwidth < 450 Then

tempMultiplier = 1 'don't change the image size

Else

tempMultiplier = 450 / currentwidth

End If

End If

Dim NewSize As New Size(CInt(currentwidth * tempMultiplier), CInt(currentheight * tempMultiplier))

Return NewSize

End Function

Link to comment
https://www.neowin.net/forum/topic/155300-image-quality-lost-on-resize-aspnet/
Share on other sites

3 answers to this question

Recommended Posts

  • 0

Well, after reading thousands of posts on image resizing, one of them helped! This is what had to bee added to the code

Dim fileName As String = albumlist.SelectedValue & "_" & currentDate & fileExtension

' Create image object from upload stream

Dim img As System.Drawing.Bitmap = System.Drawing.Bitmap.FromStream(.InputStream)

Dim imageFormat = img.RawFormat

Dim thumbSize As New Size

thumbSize = NewthumbSize(img.Width, img.Height)

'Thumb-nail the image to the new size

Dim imgOutput As New Bitmap(img, thumbSize.Width, thumbSize.Height)

'**************THIS HAD TO BE ADDED!!*****************

Dim myresizer As Graphics

myresizer = Graphics.FromImage(imgOutput)

myresizer.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic

myresizer.DrawImage(img, 0, 0, thumbSize.Width, thumbSize.Height)

'****************************************************

'Save original image

imgOutput.Save(Path.Combine(Server.MapPath("../photo/imagesileName), imageFormat)

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

    • No registered users viewing this page.
  • Posts

    • Free WinX DVD Ripper Platinum license (normally $69.95) offer ends today by Steven Parker Claim your full license (valued at $69.95) for free before the offer expires on July 25th, 2025. Grab your free licensed copy of WinX DVD Ripper Platinum (for Windows) or MacX DVD Ripper Pro (for macOS) and start backing up and digitizing your DVD collection today. Whether you’ve built a DVD library over the past decades or just want to preserve a few treasured discs, WinX DVD Ripper Platinum makes it easy to convert your physical DVDs into digital files — protecting them from scratches, damage, or loss. With just a few clicks, you can watch your favorite DVD movies on your smartphone, tablet, laptop, smart TV, or store them on an external drive or NAS for easy access anytime. This exclusive giveaway is available only for TradePub users! Get a free license for WinX DVD Ripper Platinum V8.22.2 (Windows) or MacX DVD Ripper Pro V6.8.2 (macOS) — no cost, no catch. Take this opportunity to preserve your movie collection and enjoy timeless classics wherever you go this holiday season. Main Features: Convert DVD to MP4, ISO, FLV, AVI, MOV, MP3, TV, NAS, computer, game console, iPhone, iPad, Android, etc. Supports any DVDs, including homemade DVDs, newly released DVDs, old DVDs, 99-title DVDs, non-standard DVDs, regional DVDs, workout DVDs, movie/TV Series DVDs, damaged DVDs, badly structured DVDs, etc. 1:1 DVD backup. Copy entire DVDs to ISO or VIDEO_TS folders to create complete backups, preserving the menu, movies, extras, and all other content without any changes. Fast DVD Ripping: Supports hardware acceleration, multi-core CPUs, and hyper-threading technology for quick conversions. Ripping a 2-hour DVD to MP4 (H.264/HEVC) can be completed in as little as 5 minutes. High-Quality Output: Use "Yadif Double Frames" De-interlacing Engine and High Quality Engine to ensure the good quality of the output video/audio. Edit DVD: cut, merge, crop video, add subtitle, and adjust parameters. This free license offer ends today, July 25, 2025! Download WinX DVD Ripper Platinum (worth $69.95) for free Offered by Digiarty, view other free resources The below offers are also available for free in exchange for your (work) email: Exclusive Giveaway - Get WinX DVD Ripper Platinum ($69.95 Value) FREE – Expires 7/25 Alice and Bob Learn Secure Coding ($30 Value) FREE – Expires 7/30 Building Agentic AI Systems: Create intelligent, autonomous AI agents that can reason, plan, and adapt ($38.99 Value) FREE – Expires 7/30 Aiarty Video Enhancer for PC & Mac ($49.5 Value) Free – Expires 7/31 The Ultimate Linux Newbie Guide – Featured Free content Python Notes for Professionals – Featured Free content Learn Linux in 5 Days – Featured Free content Quick Reference Guide for Cybersecurity – Featured Free content We post these because we earn commission on each lead so as not to rely solely on advertising, which many of our readers block. It all helps toward paying staff reporters, servers and hosting costs. Other ways to support Neowin The above deal not doing it for you, but still want to help? Check out the links below. Check out our partner software in the Neowin Store Buy a T-shirt at Neowin's Threadsquad Subscribe to Neowin - for $14 a year, or $28 a year for an ad-free experience Disclosure: An account at Neowin Deals is required to participate in any deals powered by our affiliate, StackCommerce. For a full description of StackCommerce's privacy guidelines, go here. Neowin benefits from shared revenue of each sale made through the branded deals site.
    • Agreed. I recall Arn Anderson, when he retired from pro wrestling, saying, "I want you to remember me as I was, not as I am!" I kinda think of Hogan the same way. I choose to remember the accomplishments in the wrestling ring, and not so much his more recent views and statements.
    • You have to look at what things are capable of causing a BSOD. Even a very poorly written game or application can't cause a BSOD, it would just crash to desktop. The two big software culprits for gaming that can cause a BSOD is the graphics driver and anti-cheat. You also have the hardware aspect of a system with poor cooling or sketchy hardware being pushed to the point of instability when gaming.
  • Recent Achievements

    • Very Popular
      d4l3d earned a badge
      Very Popular
    • Dedicated
      Stephen Leibowitz earned a badge
      Dedicated
    • Dedicated
      Snake Doc earned a badge
      Dedicated
    • One Month Later
      Philsl earned a badge
      One Month Later
    • One Month Later
      armandointerior640 earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      633
    2. 2
      ATLien_0
      243
    3. 3
      Xenon
      161
    4. 4
      +FloatingFatMan
      123
    5. 5
      neufuse
      122
  • Tell a friend

    Love Neowin? Tell a friend!