DEV Community

Cover image for Resize Bitmap without major quality loss
Adam K Dean
Adam K Dean

Posted on

Resize Bitmap without major quality loss

I'm working on a computer vision project at the moment. Whilst working on it, I've had to resize a few bitmaps due to the webcam library I'm using not being able to properly set the resolution of the camera.

I found this on StackOverflow, and it works quite well. There are a few quality differences, such loss of sharpness due to smoothing, but it's only noticeable when you put the two images side to side.

Bitmap resized = new Bitmap(desiredHeight, desiredWidth);
using (Graphics graphics = Graphics.FromImage(resized))
{
    graphics.SmoothingMode = SmoothingMode.HighQuality;
    graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
    graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
    graphics.DrawImage(originalImage,
        new Rectangle(0, 0, desiredHeight, desiredWidth));
}
pictureBox1.Image = resized;
Enter fullscreen mode Exit fullscreen mode

Like I said, works quite well, and definitely one for the snippet bin!

ACI image

ACI.dev: The Only MCP Server Your AI Agents Need

ACI.dev’s open-source tool-use platform and Unified MCP Server turns 600+ functions into two simple MCP tools on one server—search and execute. Comes with multi-tenant auth and natural-language permission scopes. 100% open-source under Apache 2.0.

Star our GitHub!

Top comments (0)

Postmark Image

The email service that speaks your language

Whether you code in Ruby, PHP, Python, C#, or Rails, Postmark's robust API libraries make integration a breeze. Plus, bootstrapping your startup? Get 20% off your first three months!

Start free

👋 Kindness is contagious

Dive into this thoughtful article, cherished within the supportive DEV Community. Coders of every background are encouraged to share and grow our collective expertise.

A genuine "thank you" can brighten someone’s day—drop your appreciation in the comments below!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found value here? A quick thank you to the author makes a big difference.

Okay