none
[C#] Image gets blurry after resizing it

    Question

  • In my project I want to resize an Image using a Bitmap. Here's what my code looks like:

    Size imageSize = new Size(300, 300);
    
    Bitmap bmp2 = new Bitmap(Properties.Resources.Circle, imageSize);
    
                bgc = BufferedGraphicsManager.Current;
                bg = bgc.Allocate(z, frm.DisplayRectangle);
    
                bg.Graphics.Clear(frm.BackColor);
                
                frm.Refresh();
    
                bg.Graphics.DrawImage(bmp2, frm.Width / 2 - imageSize.Width / 2, frm.Height / 2 - imageSize.Height / 2);
    
                bg.Render(z);

    Now the problem is the following:

    The original image is 16x16 and looks like this:


    But when I resize the image in the code, it gets this blurry effect that I want to get rid off:

    I'd be very thankful if you could help me.


    • Edited by XzerT Tuesday, April 16, 2019 9:16 AM
    Tuesday, April 16, 2019 9:08 AM

Answers

  • You can change

    InterpolationMode (NearestNeighbor)
    SmoothingMode (Default)

    but the result won't be great for a 16*16 image resized to 300*300...

    • Marked as answer by XzerT Tuesday, April 16, 2019 6:13 PM
    Tuesday, April 16, 2019 10:16 AM

All replies

  • You can change

    InterpolationMode (NearestNeighbor)
    SmoothingMode (Default)

    but the result won't be great for a 16*16 image resized to 300*300...

    • Marked as answer by XzerT Tuesday, April 16, 2019 6:13 PM
    Tuesday, April 16, 2019 10:16 AM
  • That is bound to happen, here is a 16x16 shown as 300x300, the blur is actually the letter W.

    original


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Tuesday, April 16, 2019 11:03 AM
    Moderator
  • Ok thanks for your answer!

    You said that the result woudn't be great for resizing an image from 16x16 to 300x300... What can I do to get the best result other than resizing it?

    Tuesday, April 16, 2019 6:13 PM
  • You said that the result woudn't be great for resizing an image from 16x16 to 300x300... What can I do to get the best result other than resizing it?

    I tested NearestNeighbor (equivalent) and No Smoothing mode with Paint Shop Pro and in c#

    with a similar 16*16 image

    The result is the same, no more blur effect, but it is not perfect when you resize an image so much

    If the image is regular, it is ok :

    Original image, InterpolationMode.HighQualityBilinear, InterpolationMode.NearestNeighbor =>

    • Edited by Castorix31 Tuesday, April 16, 2019 8:24 PM
    Tuesday, April 16, 2019 7:27 PM