如何覆盖两个picturebox c#但是可以看到背景中的picturebox

如何覆盖两个picturebox c#但是可以看到背景中的picturebox,c#,C#,你好 我不知道我的标题是否正确。对不起,我英语不好 如何使用c#ino覆盖两个picturebox以获得下面的图像,并在运行时更改上部图片框的不透明度 我需要达到的是这样的目标。我有两个图像,我需要覆盖它们 第一张图片: 我有第二张图片,文字是:图片上的另一个文字。 并且文本的位置低于第一图像的文本位置 (我不能上传两张以上的图片,因为我还没有10张照片。) 我需要像下面的图像一样,但使用两个picturebox,可以改变不透明度,以便看到第一个picturebox下面的第二个pictureb

你好

我不知道我的标题是否正确。对不起,我英语不好

如何使用c#ino覆盖两个picturebox以获得下面的图像,并在运行时更改上部图片框的不透明度

我需要达到的是这样的目标。我有两个图像,我需要覆盖它们

第一张图片:

我有第二张图片,文字是:图片上的另一个文字。 并且文本的位置低于第一图像的文本位置 (我不能上传两张以上的图片,因为我还没有10张照片。)

我需要像下面的图像一样,但使用两个picturebox,可以改变不透明度,以便看到第一个picturebox下面的第二个picturebox

以及两幅图像的输出:

我使用java创建了输出图像。我知道我可以使用c#运行jar文件。但是用户需要在运行时更改不透明度。那我该怎么做呢

这是我使用的java代码

BuffereImage biInner=图像IO.read(内部); BufferedImage biOutter=图像IO.read(输出)


我希望我的问题可以理解。谢谢

给你,只是一个样本,但blueBox是透明的(0.5):

公共密封部分类表格1:表格
{
私有只读位图m_BlueBox;
私有只读位图m_YellowBox;
公共表格1()
{
初始化组件();
双缓冲=真;
m_YellowBox=CreateBox(颜色为黄色);
m_BlueBox=CreateBox(Color.Blue);
m_蓝盒=变化不透明度(m_蓝盒,0.5f);
}
公共静态位图更改不透明度(图像img、浮点不透明度值)
{
var bmp=新位图(img.Width、img.Height);
使用(var graphics=graphics.FromImage(bmp))
{
var colormatrix=新的colormatrix();
colormatrix.Matrix33=不透明值;
var imgatAttribute=新的ImageAttributes();
SetColorMatrix(colormatrix,ColorMatrixFlag.Default,ColorAdjustType.Bitmap);
graphics.DrawImage(img,新矩形(0,0,bmp.Width,bmp.Height),0,0,img.Width,img.Height,
GraphicsUnit.Pixel,imgatAttribute);
}
返回bmp;
}
专用静态位图CreateBox(彩色)
{
var bmp=新位图(200200);
对于(var x=0;x
Sample我试试看。谢谢,我试过了你发的链接上的代码,先生。我在上面放了一个同样大小的图片盒。但是picturebox有不同的图像。然后我试着运行这个程序。但是我看不到下面的图片盒。我甚至改变了顶部picturebox的透明度,但看不到下面的图像。我怎样才能做到呢?谢谢。net控件中没有透明度。您必须使用wpf来完成此操作。上面的示例只是设置图像的透明度,而不是控件。使用1个picturebox,使用事件绘制,您可以像在代码中一样绘制图像
    System.out.println(biInner);
    System.out.println(biOutter);

    Graphics2D g = biOutter.createGraphics();
    g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));
    int x = (biOutter.getWidth() - biInner.getWidth()) / 2;
    int y = (biOutter.getHeight() - biInner.getHeight()) / 2;
    System.out.println(x + "x" + y);
    g.drawImage(biInner, x, y, null);
    g.dispose();

    ImageIO.write(biOutter, "PNG", new File(output));
  public sealed partial class Form1 : Form
  {
    private readonly Bitmap m_BlueBox;
    private readonly Bitmap m_YellowBox;

    public Form1()
    {
      InitializeComponent();
      DoubleBuffered = true;
      m_YellowBox = CreateBox(Color.Yellow);
      m_BlueBox = CreateBox(Color.Blue);
      m_BlueBox = ChangeOpacity(m_BlueBox, 0.5f);
    }

    public static Bitmap ChangeOpacity(Image img, float opacityvalue)
    {
      var bmp = new Bitmap(img.Width, img.Height);
      using (var graphics = Graphics.FromImage(bmp))
      {
        var colormatrix = new ColorMatrix();
        colormatrix.Matrix33 = opacityvalue;
        var imgAttribute = new ImageAttributes();
        imgAttribute.SetColorMatrix(colormatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
        graphics.DrawImage(img, new Rectangle(0, 0, bmp.Width, bmp.Height), 0, 0, img.Width, img.Height,
          GraphicsUnit.Pixel, imgAttribute);
      }
      return bmp;
    }

    private static Bitmap CreateBox(Color color)
    {
      var bmp = new Bitmap(200, 200);
      for (var x = 0; x < bmp.Width; x++)
      {
        for (var y = 0; y < bmp.Height; y++)
        {
          bmp.SetPixel(x, y, color);
        }
      }
      return bmp;
    }

    private void Form1_Paint(object sender, PaintEventArgs e)
    {
      e.Graphics.DrawImage(m_YellowBox, new Point(10, 10));
      e.Graphics.DrawImage(m_BlueBox, new Point(70, 70));
    }
  }