绘制与GDI自定义透明度的图像+ [英] Draw an image with custom transparency in GDI+
问题描述
我抽签影像(所有的尺寸= 24×24像素格式= 32BppPArgb)上使用Drawing.Graphics对象和的DrawImage()功能的控制。这是可能的缩小在我的应用程序,这意味着Graphics对象已变换矩阵连接到它控制缩放和平移。
I'm drawing lots of images (all of them dimensions=24x24 pixelformat=32BppPArgb) onto a Control using a Drawing.Graphics object and the DrawImage() function. It's possible to zoom out in my application which means that the Graphics object has a Transform Matrix attached to it which controls both zooming and panning.
有一个在当变焦低于50%绘制这些图标是没有意义的,但我想从图纸图标过渡到不绘制图标顺畅。即,起始于70%,图标应当与另外的透明度因子绘制,以便它们将变得完全透明,在50%。
There's no point in drawing these icons when the zoom drops below 50%, but I'd like to make the transition from drawing icons to not drawing icons smoother. I.e., starting at 70%, icons should be drawn with an additional transparency factor so that they will become completely transparent at 50%.
我如何可以得出一个额外的透明位图没有它采取显著长于的DrawImage()?
How can I draw a bitmap with an additional transparency without it taking significantly longer than DrawImage()?
谢谢, 大卫
推荐答案
您只需要创建一个合适的嘉洛斯,初始化一个ImageAttributes对象与它传递ImageAttributes对象以Graphics.DrawImage的重载版本之一。此示例将会给你50%transparancy:
You just create an appropriate ColorMatrix, initialize a ImageAttributes object with it and pass that ImageAttributes object to one of the overloaded version of Graphics.DrawImage. This sample will give you 50% transparancy:
float[][] matrixAlpha =
{
new float[] {1, 0, 0, 0, 0},
new float[] {0, 1, 0, 0, 0},
new float[] {0, 0, 1, 0, 0},
new float[] {0, 0, 0, 0.5f, 0},
new float[] {0, 0, 0, 0, 1}
};
ColorMatrix colorMatrix = new ColorMatrix( matrixAlpha );
ImageAttributes iaAlphaBlend = new ImageAttributes();
iaAlphaBlend.SetColorMatrix(
colorMatrix,
ColorMatrixFlag.Default,
ColorAdjustType.Bitmap );
这篇关于绘制与GDI自定义透明度的图像+的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!