2
A
回答
6
您必须使用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;
}
1
感谢汉斯帕桑特 这是非常有用的!它救了我的时间
我已经转换你的代码到VB
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.Windows.Forms
Public Class BlendPanel
Inherits Panel
Public Sub New()
DoubleBuffered = True
End Sub
Public Property Image1() As Image
Get
Return mImg1
End Get
Set
mImg1 = value
Invalidate()
End Set
End Property
Public Property Image2() As Image
Get
Return mImg2
End Get
Set
mImg2 = value
Invalidate()
End Set
End Property
Public Property Blend() As Single
Get
Return mBlend
End Get
Set
mBlend = value
Invalidate()
End Set
End Property
Protected Overrides Sub OnPaint(e As PaintEventArgs)
If mImg1 Is Nothing OrElse mImg2 Is Nothing Then
e.Graphics.FillRectangle(New SolidBrush(Me.BackColor), New Rectangle(0, 0, Me.Width, Me.Height))
Else
Dim rc As New Rectangle(0, 0, Me.Width, Me.Height)
Dim cm As New ColorMatrix()
Dim ia As 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)
End If
MyBase.OnPaint(e)
End Sub
Private mImg1 As Image
Private mImg2 As Image
Private mBlend As Single
End Class
相关问题
- 1. JButton的不透明度/半透明度?
- 2. 整体SVG不透明度/透明度
- 3. 不透明度
- 4. CSS过渡:不透明度不透明。 。
- 5. GMSMarker不透明度不透明动画
- 6. 不透明度使div更不透明
- 7. 按钮不透明/透明度
- 8. 与不透明度
- 9. 不透明度与
- 10. ccDrawLine不透明度?
- 11. SDL_Texture不透明度
- 12. Dat.gui不透明度
- 13. UIView不透明度梯度
- 14. 更改不透明度时重绘窗口不透明度
- 15. c#winform不透明度70%,但面板内不透明度100%
- 16. Div 70%不透明度,含有100%不透明度的图像
- 17. 段落中的不透明度变化改变了文本的不透明度和背景不透明度
- 18. C#控制台不透明度/透明度
- 19. 不透明度的文本透明度CSS
- 20. 我需要不透明度(透明度)的IMG与CSS ie8
- 21. Java中的图像透明度或不透明度问题
- 22. 更改jButton透明度/不透明度/ alpha
- 23. 返回的内容的不透明度低透明度DIV中
- 24. 图像的不透明度/透明度左至反之亦然
- 25. Firefox不透明度(透明度)渐变 - 淡出图像
- 26. CSS不透明度动画
- 27. 键盘不透明度
- 28. 元素的不透明度
- 29. AbcPdf不透明度AddImageHtml
- 30. CSS不透明度为ARGB