gpt4 book ai didi

vb.net - .DrawImage 具有不透明度?

转载 作者:行者123 更新时间:2023-12-02 00:10:33 26 4
gpt4 key购买 nike

g.DrawImage

是的,在我的图片框中画一个图像。是否可以给它一个不透明属性?我一直在查看 DrawImage 的其他版本,但找不到这样的东西!

最佳答案

您必须使用 ColorMatrix 来混合图像。这是我不久前编写的一个 C# 控件,它向您展示了您需要的基本代码。不是 VB.NET 代码,但是,嘿,您也没有真正努力:

using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;

public class BlendPanel : Panel {
public BlendPanel() {
DoubleBuffered = true;
}
public Image Image1 {
get { return mImg1; }
set { mImg1 = value; Invalidate(); }
}
public Image Image2 {
get { return mImg2; }
set { mImg2 = value; Invalidate(); }
}
public float Blend {
get { return mBlend; }
set { mBlend = value; Invalidate(); }
}
protected override void OnPaint(PaintEventArgs e) {
if (mImg1 == null || mImg2 == null)
e.Graphics.FillRectangle(new SolidBrush(this.BackColor), new Rectangle(0, 0, this.Width, this.Height));
else {
Rectangle rc = new Rectangle(0, 0, this.Width, this.Height);
ColorMatrix cm = new ColorMatrix();
ImageAttributes ia = new ImageAttributes();
cm.Matrix33 = mBlend;
ia.SetColorMatrix(cm);
e.Graphics.DrawImage(mImg2, rc, 0, 0, mImg2.Width, mImg2.Height, GraphicsUnit.Pixel, ia);
cm.Matrix33 = 1F - mBlend;
ia.SetColorMatrix(cm);
e.Graphics.DrawImage(mImg1, rc, 0, 0, mImg1.Width, mImg1.Height, GraphicsUnit.Pixel, ia);
}
base.OnPaint(e);
}
private Image mImg1;
private Image mImg2;
private float mBlend;
}

关于vb.net - .DrawImage 具有不透明度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5519956/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com