【问题标题】:Image transparecy with another one backwards c#图像透明度与另一个向后 c#
【发布时间】:2014-04-18 10:37:43
【问题描述】:

我目前在图像背景前有一些图像 (4),问题是图像形状与其他图像相冲突,并且它们之间的透明度效果不佳。

好的,我已将这 4 个图像的背景色设置为透明,然后将每个图像的父级设置为背景图像,但这就是我所看到的:

Imgur

好像只刷新他们的父级(Background)有些帮助?

【问题讨论】:

  • 原始图像是什么样的?
  • 最终结果应该是这样的:Imgur,表格中的图片是这样的:Imgur

标签: c# image forms background transparent


【解决方案1】:

我怀疑您正在添加图片框或类似的东西,但这会使其工作效率非常低。

您可能需要考虑创建一个对象来处理图像绘制并将其添加到具有背景图像的基本控件中,如下所示:

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 或名称,以便区分它们。

顺便说一句...我在这里写了代码没有测试,但我认为重要的部分都在这里。

【讨论】:

  • 抱歉,我该如何调用 picturebox_Paint 事件?谢谢:D
  • @Edgar_94_,我将编辑帖子并添加事件挂钩。如果你有一个继承自图片框的类,你可以重写 OnPaint。
  • 成功了,谢谢!但我希望黄色的家伙在背景图像上移动并在该移动中设置动画,我有一个用图片框做到这一点的课程,但我不知道如何用 g.DrawImage 做到这一点,非常感谢:D
猜你喜欢
  • 1970-01-01
  • 2011-07-20
  • 2016-03-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-04-04
  • 2020-05-31
相关资源
最近更新 更多