mirror of
https://github.com/ShareX/ShareX.git
synced 2024-09-30 01:07:21 +13:00
Fix background image quality
This commit is contained in:
parent
99791f7af4
commit
d63150718b
1 changed files with 13 additions and 10 deletions
|
@ -513,29 +513,32 @@ public static Bitmap AddBackgroundImage(Bitmap bmp, Bitmap backgroundImage)
|
|||
using (bmp)
|
||||
using (backgroundImage)
|
||||
{
|
||||
Bitmap result = new Bitmap(bmp.Width, bmp.Height);
|
||||
Bitmap bmpResult = bmp.CreateEmptyBitmap();
|
||||
|
||||
float aspectRatio = (float)backgroundImage.Width / backgroundImage.Height;
|
||||
|
||||
int width = result.Width;
|
||||
int width = bmpResult.Width;
|
||||
int height = (int)(width / aspectRatio);
|
||||
|
||||
if (height < result.Height)
|
||||
if (height < bmpResult.Height)
|
||||
{
|
||||
height = result.Height;
|
||||
height = bmpResult.Height;
|
||||
width = (int)(height * aspectRatio);
|
||||
}
|
||||
|
||||
int centerX = (result.Width - width) / 2;
|
||||
int centerY = (result.Height - height) / 2;
|
||||
int centerX = (bmpResult.Width - width) / 2;
|
||||
int centerY = (bmpResult.Height - height) / 2;
|
||||
|
||||
using (Graphics graphics = Graphics.FromImage(result))
|
||||
using (Graphics g = Graphics.FromImage(bmpResult))
|
||||
{
|
||||
graphics.DrawImage(backgroundImage, centerX, centerY, width, height);
|
||||
graphics.DrawImage(bmp, 0, 0, bmp.Width, bmp.Height);
|
||||
g.SetHighQuality();
|
||||
g.PixelOffsetMode = PixelOffsetMode.Half;
|
||||
|
||||
g.DrawImage(backgroundImage, centerX, centerY, width, height);
|
||||
g.DrawImage(bmp, 0, 0, bmp.Width, bmp.Height);
|
||||
}
|
||||
|
||||
return result;
|
||||
return bmpResult;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue