我目前在图像背景前有一些图像 (4),问题是图像形状与其他图像发生碰撞,并且它们之间的透明度效果不佳。
好的,我已经将这 4 个图像的背景色设置为透明,然后为每个背景图像设置父级,但这是我看到的:
好像只有刷新自己的父级(Background)有帮助?
最佳答案
我怀疑您要添加图片框或类似的东西,但这会使工作效率非常低。
您可能需要考虑创建一个对象来处理图像绘制并将其添加到具有背景图像的基本控件中,如下所示:
public class YellowGuy
{
public Point Position {get; set;}
public Size Size {get; set;}
public Bitmap YellowGuyImage {get; set;}
public YellowGuy(Bitmap img, Point startPos, Size desiredSize)
{
YellowGuyImage = img;
Size = desiredSize;
Position = startPos;
}
public void Draw(Graphics g)
{
g.DrawImage(YellowGuyImage, new rectangle(Position, Size));
}
}
在你的主窗体中(也许,我不知道你的代码):
picturebox.Paint += new System.Windows.Forms.PaintEventHandler(this.picturebox_Paint);
List<YellowGuy> yellowGuys;
yellowGuys = new List<YellowGuy>();
yellowGuys.Add(new YellowGuy([some image],[some position],[some size])); //Do on a for, or how you wish, to add more guys.
//Control which draw images, here I used PictureBox to show you
private void picturebox_Paint(object sender, PaintEventArgs e)
{
foreach(var guy in yellowGuys)
{
guy.Draw(e.Graphics);
}
}
你可以重新定位一个访问列表的黄色人并改变位置,在下一次刷新时它将被绘制在新位置。 您可能希望向 YellowGuy 对象添加 ID 或名称,以便区分它们。
顺便说一句...我在这里写的代码没有测试,但我认为重要的部分都在这里。
关于c# - 图像透明度与另一个向后 c#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22382952/