background图片叠加,C#将图像叠加在另一个图像上

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.

fsyN4.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.

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

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..

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值