现在我有一个表格,表格PictureBox
上有一个。我正在使用两个部分透明的图像,并试图将一个放在另一个之上。
- sideMenuWide = 带透明背景的圆角矩形 (.png) [底部图像]
- labelPointer = 具有透明背景的三角形 (.png) [顶部图片]
这是我的方法:
// METHOD #1 //
Image img1 = Image.FromFile(@"C:\sideMenuWide.png");
Image img2 = Image.FromFile(@"C:\labelPointer.png");
picBox.Image = CombineImages(img1, img2);
// METHOD #2 //
Image imgA = RBS.Properties.Resources.sideMenuWide;
Image imgB = RBS.Properties.Resources.labelPointer;
picBox.Image = CombineImages(imgA, imgB);
还有CombineImage函数:(这个函数我没写,只修改)
public static Bitmap CombineImages(Image imgA, Image imgB)
{
//a holder for the result (By default, use the first image as the main size)
Bitmap result = new Bitmap(imgA.Size.Width, imgA.Size.Height);
//use a graphics object to draw the resized image into the bitmap
using (Graphics graphics = Graphics.FromImage(result))
{
//set the resize quality modes to high quality
graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
//draw the images into the target bitmap
graphics.DrawImage(imgA, 0, 0, imgA.Width, imgA.Height);
graphics.DrawImage(imgB, 100, 70, imgB.Width, imgB.Height);
}
return result;
}
方法 #1可以按照我的意愿工作,在 imgA 上完美显示 imgB。
然而,方法#2显示 imgA 很好,但 imgB 真的很微弱。
关于如何克服这个问题的任何想法?我希望能够使用资源来做到这一点,而不必从文件中提取。