110,545
社区成员
发帖
与我相关
我的任务
分享
private float m_fOpacity = 1.0f;
private Image m_image = 初始化图片;
//在绘图事件中调用该方法
private void DrawOpacityImage(Graphics g)
{
ImageAttributes imageAttributes = new ImageAttributes();
ColorMap colorMap = new ColorMap();
colorMap.OldColor = Color.FromArgb(255, 0, 255, 0);
colorMap.NewColor = Color.FromArgb(0, 0, 0, 0);
ColorMap[] remapTable = { colorMap };
imageAttributes.SetRemapTable(remapTable, ColorAdjustType.Bitmap);
float[][] colorMatrixElements = {
new float[] {1.0f, 0.0f, 0.0f, 0.0f, 0.0f},
new float[] {0.0f, 1.0f, 0.0f, 0.0f, 0.0f},
new float[] {0.0f, 0.0f, 1.0f, 0.0f, 0.0f},
new float[] {0.0f, 0.0f, 0.0f, this.m_fOpacity, 0.0f},
new float[] {0.0f, 0.0f, 0.0f, 0.0f, 0.1f}};
ColorMatrix wmColorMatrix = new ColorMatrix(colorMatrixElements);
imageAttributes.SetColorMatrix(wmColorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
Rectangle imageBounds = new Rectangle(0, 0, this.m_image.Width, this.m_image.Height);
try
{
g.DrawImage(this.m_image, imageBounds, 0, 0, imageBounds.Width, imageBounds.Height, GraphicsUnit.Pixel, imageAttributes);
}
catch { }
}
private void trackBar1_ValueChanged(object sender, EventArgs e)
{
this.m_fOpacity += 0.1f; //这里调整透明度
this.绘图控件.Invalidate();
}