C#将图像叠加在另一个图像上 [英] c# overlay an image on top of another

查看:1616
本文介绍了C#将图像叠加在另一个图像上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试将注释放在员工图片上方.但是,注释背景被设置为表单背景,如图中所示. 使用的图像类型是png.

i am currently trying to put the notes on top of the staff image. However, the notes background are being set to the form background as shown in the image. image type used is png.

//class music staff
  public MusicStaff(int xLoc, int yLoc, int xSize, int ySize)
        {
            this.SetBounds(xLoc, yLoc, xSize, ySize);
            this.Visible = true;
            ResourceManager rm = Resources.ResourceManager;

            Bitmap bmp = (Bitmap)rm.GetObject("Staff1");
            this.BackgroundImage = bmp;
            this.BackgroundImageLayout = ImageLayout.Stretch;
            this.BackColor = Color.White;
//adding the background pic
   panel4 = new MusicStaff(3, 62, 927, 150);

//adding a note
 MusicNote p = new MusicNote(pitch, duration, shape, s);

            p.SizeMode = PictureBoxSizeMode.StretchImage;
            p.BackColor = Color.Transparent;
            p.Size = new Size(50, 75);
 p.Location = new Point(xCounter + starterX, NoteLocations.c0.mainPoint);
                        Bitmap myImage = (Bitmap)rm.GetObject(shape);
                        p.Image = myImage;

推荐答案

您并没有真正叠加图像.您正在用图像覆盖控件.

You are not really overlaying images. You are overlaying controls with images.

要使其具有透明性,您的笔记控件需要嵌套在人员控件中!

For this to work with transparency, your notes controls need to be nested in the staff control!

并非如此,透明度显示的是其实际父级的颜色,即表单的颜色.

As they aren't, the transparency shows the color of their actualy parent, i.e. the form.

设置p.Parent=panel4并相应地调整位置,即使其相对于人员.

Set p.Parent=panel4 and adapt the locations accordingly, i.e. make them relative to the staff..

这是winforms透明性的限制,它不支持重叠控件. 嵌套控件可以正常工作,但只能通过从父级复制透明部分来伪造.

This is a limitation of winforms transparency, which doesn't support overlapping controls. Nested controls will work fine but only by faking the transparent parts by copying them from the parent..

请注意,结果将无法使音符彼此重叠或被任何其他控件重叠.

Note that as a consequence you will not be able to have the notes overlap each other or be overlapped by any other controls.

通常放弃使用控件是更好的方法;取而代之的是可以简单地绘制出组成总数的所有部分.

Often giving up on using controls is the better way; instead one can simply draw all parts that make up the total..

因此您可以在panel4_Paint事件中执行一系列e.Graphics.DrawImage(noteImg, x, y).

So you could do a series of e.Graphics.DrawImage(noteImg, x, y) in the panel4_Paint event.

这篇关于C#将图像叠加在另一个图像上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆