Hack Forums
[C#] Cleaner Pictures in PictureBox - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [C#] Cleaner Pictures in PictureBox (/showthread.php?tid=5748023)



Cleaner Pictures in PictureBox - JUSTIN - Nov 4, 2017

I've had this issue for a while.
When I tried to use icons/pictures on windows forms, they'd often have pretty pixelated edges.
Here's a neat way to fix it using a custom component which allows you to use the base PictureBox with some custom properties.

Code
public class CPictureBox : PictureBox
{
    public InterpolationMode InterpolationMode { get; set; }
    public PixelOffsetMode PixelOffsetMode { get; set; }

    protected override void OnPaint(PaintEventArgs paintEventArgs)
    {
        paintEventArgs.Graphics.InterpolationMode = InterpolationMode;
        paintEventArgs.Graphics.PixelOffsetMode = PixelOffsetMode;
        base.OnPaint(paintEventArgs);
    }
}
For best results:
Code
InterpolationMode: HighQualityBilinear
PixelOffsetMode: HighQuality

Pictures (Click to View)
Concept taken from here, I basically just added the PixelOffsetMode and figured some people on here might find it useful.


RE: Cleaner Pictures in PictureBox - gigajew - Nov 5, 2017

Good contribution, I'm sure this will help a lot of people


RE: Cleaner Pictures in PictureBox - He B TeMy - Nov 7, 2017

Another good way of displaying clear pictures on a picture box is to get a picture with a size multiplier above and resize it to the picture box size.

Example: Picturebox is 480p in size, you get a 720p or 1080p picture and feed it to the picture box and then adjust to the picturebox size, this has the disadvantage of you having to use some extra space, but a couple of MB's in a normal app is pratically nothing.

I'm not saying your way of doing it isn't good OP.


RE: Cleaner Pictures in PictureBox - 0xDEAD10CC - Nov 7, 2017

(Nov 7, 2017 06:33 AM)ff20 Wrote:  Another good way of displaying clear pictures on a picture box is to get a picture with a size multiplier above and resize it to the picture box size.

Example: Picturebox is 480p in size, you get a 720p or 1080p picture and feed it to the picture box and then adjust to the picturebox size, this has the disadvantage of you having to use some extra space, but a couple of MB's in a normal app is pratically nothing.

I'm not saying your way of doing it isn't good OP.

Lol resolution does not describe the size of a box though. But this is a fair point nonetheless.


RE: Cleaner Pictures in PictureBox - Butane - Nov 7, 2017

Making the picturebox sizemode to zoom does the same thing right?


RE: Cleaner Pictures in PictureBox - debug - Nov 9, 2017

This is really useful, thanks. I've experienced this same issue before.