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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:25:22+00:00 2026-06-06T12:25:22+00:00

I’ve spent quite a long time Googling this and read various articles but I

  • 0

I’ve spent quite a long time Googling this and read various articles but I seem to have run myself round in circles and am now very confused, and don’t seem to have managed to get anywhere!

I am trying to get 4 different sized versions of an image, to achieve this, I have an array of sizes and am looping the function below.

This works, and does everything expected, except, the smaller images are very blocky and I can’t get the smoothing to achieve the effect I’d expect.

With old-school ASP Classic, I used Persits ASPUpload/jpeg plugin and it did nice, smooth resizing. With .NET I am struggling.

Public Shared Sub ResizeImages(FileName, NewFileName, maxWidth, maxHeight, uploadDir, qualityPercent)

    Dim originalImg As System.Drawing.Image = System.Drawing.Image.FromFile(uploadDir & FileName)

    Dim aspectRatio As Double
    Dim newHeight As Integer
    Dim newWidth As Integer

    '*** Calculate Size ***'
    If originalImg.Width > maxWidth Or originalImg.Height > maxHeight Then
        If originalImg.Width >= originalImg.Height Then ' image is wider than tall
            newWidth = maxWidth
            aspectRatio = originalImg.Width / maxWidth
            newHeight = originalImg.Height / aspectRatio
        Else ' image is taller than wide
            newHeight = maxHeight
            aspectRatio = originalImg.Height / maxHeight
            newWidth = originalImg.Width / aspectRatio
        End If
    Else ' if image is not larger than max then keep original size
        newWidth = originalImg.Width
        newHeight = originalImg.Height
    End If

    Dim newImg As New Bitmap(originalImg, CInt(newWidth), CInt(newHeight)) '' blank canvas
    Dim canvas As Graphics = Graphics.FromImage(newImg) 'graphics element

    '*** compress ***'
    Dim myEncoderParameters As EncoderParameters
    myEncoderParameters = New EncoderParameters(1)
    ' set quality level based on "resolution" variable
    Dim myEncoderParameter = New EncoderParameter(System.Drawing.Imaging.Encoder.Quality, CType(qualityPercent, Int32))
    myEncoderParameters.Param(0) = myEncoderParameter

    '*** Save As  ***'
    canvas.SmoothingMode = Drawing.Drawing2D.SmoothingMode.AntiAlias
    canvas.DrawImage(newImg, New Point(0, 0))
    newImg.Save(uploadDir & NewFileName, getCodec("image/jpeg"), myEncoderParameters)

    '*** Close ***'
    originalImg.Dispose()
    newImg.Dispose()
    '*** Nothing ***'
    newImg = Nothing
    originalImg = Nothing

End Sub

Public Shared Function getCodec(getThis) As Drawing.Imaging.ImageCodecInfo
    Dim output As Drawing.Imaging.ImageCodecInfo
    Dim codecs As Imaging.ImageCodecInfo() = Imaging.ImageCodecInfo.GetImageEncoders
    For Each codec As Imaging.ImageCodecInfo In codecs
        If codec.MimeType = getThis Then
            output = codec
        End If
    Next codec
    Return output
End Function

I feel like I might be mixing up Types here?

I have a System.Drawing.Image, a BitMap and a Graphic object during the course of the function above, and feel that I might be trying to apply to the smoothing to the wrong element, or at the wrong stage of the coding?

The System.Drawing.Image object loads the file that’s saved on the server, then I calculate the aspect ratio and new size required, create a new BitMap of this size and save it to a Graphics object.

Is this correct?

What do I need to amend to achieve a smoother resize?

As usual, any help much 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-06-06T12:25:24+00:00Added an answer on June 6, 2026 at 12:25 pm

    try use InterpolationMode

    Private imgSource As System.Drawing.Image
    Private imgOutput As System.Drawing.Image
    Public Function Resize(ByVal intPercent As Integer, ByVal intType As Integer)
        'resize the image by percent
        Dim intX, intY As Integer
        intX = Int(imgSource.Width / 100 * intPercent)
        intY = Int(imgSource.Height / 100 * intPercent)
        Dim bm As Drawing.Bitmap = New System.Drawing.Bitmap(intX, intY)
        Dim g As System.Drawing.Graphics = Drawing.Graphics.FromImage(bm)
    
        Select Case intType
            Case 0
                g.InterpolationMode = Drawing.Drawing2D.InterpolationMode.Default
            Case 1
                g.InterpolationMode = Drawing.Drawing2D.InterpolationMode.High
            Case 2
                g.InterpolationMode = Drawing.Drawing2D.InterpolationMode.HighQualityBilinear
            Case 3
                g.InterpolationMode = Drawing.Drawing2D.InterpolationMode.HighQualityBicubic
        End Select
    
        g.DrawImage(imgSource, 0, 0, intX, intY)
        imgOutput = bm
    
    End Function
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
This could be a duplicate question, but I have no idea what search terms
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I need to clean up various Word 'smart' characters in user input, including but
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.