I need to resize user provided image using picturebox with size 48X48 pixels. I "googled" and found the following sample code:

Using DrawImage

FileStream loFileStream = new FileStream(@".\RefreshCL.png", FileMode.Open, FileAccess.Read);
Image loOriginalImage = Bitmap.FromStream(loFileStream);           
Bitmap loBitmap = new Bitmap(48, 48);

using (Graphics g = Graphics.FromImage((Image)loBitmap))
{
    g.DrawImage(loOriginalImage, 0,0, 48,48);
    pictureEdit1.Image = loBitmap;
}
As we can see the result as above, it is not good. The image is broken

 

I "googled" again and get this code

Using GetThumbnailImage

FileStream loFileStream = new FileStream(@".\RefreshCL.png", FileMode.Open, FileAccess.Read);
            
Image loOriginalImage = Bitmap.FromStream(loFileStream);

loOriginalImage = loOriginalImage.GetThumbnailImage(48, 48, new Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero);

pictureEdit1.Image = loOriginalImage;

public bool ThumbnailCallback()
{
    return true;
}

As this is much better.