【发布时间】:2014-04-18 10:37:43
【问题描述】:
我目前在图像背景前有一些图像 (4),问题是图像形状与其他图像相冲突,并且它们之间的透明度效果不佳。
好的,我已将这 4 个图像的背景色设置为透明,然后将每个图像的父级设置为背景图像,但这就是我所看到的:
好像只刷新他们的父级(Background)有些帮助?
【问题讨论】:
标签: c# image forms background transparent
我目前在图像背景前有一些图像 (4),问题是图像形状与其他图像相冲突,并且它们之间的透明度效果不佳。
好的,我已将这 4 个图像的背景色设置为透明,然后将每个图像的父级设置为背景图像,但这就是我所看到的:
好像只刷新他们的父级(Background)有些帮助?
【问题讨论】:
标签: c# image forms background transparent
我怀疑您正在添加图片框或类似的东西,但这会使其工作效率非常低。
您可能需要考虑创建一个对象来处理图像绘制并将其添加到具有背景图像的基本控件中,如下所示:
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 或名称,以便区分它们。
顺便说一句...我在这里写了代码没有测试,但我认为重要的部分都在这里。
【讨论】: