1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace KeePassRPC
{
public static class DpiFix
{
public static Image ScaleImageTo16x16(Image img, bool bForceNewObject)
{
if (img == null) { Debug.Assert(false); return null; }
int w = img.Width;
int h = img.Height;
int sw = 16;
int sh = 16;
if ((w == sw) && (h == sh) && !bForceNewObject)
return img;
Bitmap bmp = new Bitmap(sw, sh, img.PixelFormat);
using (Graphics g = Graphics.FromImage(bmp))
{
g.SmoothingMode = SmoothingMode.HighQuality;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
RectangleF rSource = new RectangleF(0, 0, w, h);
RectangleF rDest = new RectangleF(0, 0, sw, sh);
// Prevent border drawing bug
rSource.Offset(-0.5f, -0.5f);
g.DrawImage(img, rDest, rSource, GraphicsUnit.Pixel);
return bmp;
}
}
}
}
|