c# - 图像透明度与另一个向后 c#

标签 c# image forms background transparent

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

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

Imgur

好像只有刷新自己的父级(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/

相关文章:

image - 在fabric js中更改png图像颜色

jQuery 在提交时更改值

javascript - <asp :Button> event not firing when within element affected by jQuery

c# - 如何将通过反射获得的方法分配给委托(delegate)? (或 : how to speed up method calls through reflection)

c# - Blazor - 集合的双向绑定(bind)

image - 最大池化 VS 求和池化

JavaScript onClick 方法更改图像的 CSS 属性

javascript - JQuery表单提交生成一个新表单

javascript - Show (Visible/Hidden NOT Show/Hide) 基于表单选择框选择的 HTML 元素

c# - Razor 循环项的索引