/// <summary>
/// Draws an image with transparency
/// </summary>
/// <param name="gx">Graphics to drawn on.</param>
/// <param name="image">Image to draw.</param>
/// <param name="transparency">Transparency constant</param>
/// <param name="x">X location</param>
/// <param name="y">Y location</param>
public static void DrawAlpha(this Graphics gx, Bitmap image,
byte transparency, int x, int y)
{
using (Graphics gxSrc = Graphics.FromImage(image))
{
IntPtr hdcDst = gx.GetHdc();
IntPtr hdcSrc = gxSrc.GetHdc();
BlendFunction blendFunction = new BlendFunction();
// Only supported blend operation
blendFunction.BlendOp = (byte)BlendOperation.AC_SRC_OVER;
// Documentation says put 0 here
blendFunction.BlendFlags = (byte)BlendFlags.Zero;
// Constant alpha factor
blendFunction.SourceConstantAlpha = transparency;
// Don't look for per pixel alpha
blendFunction.AlphaFormat = (byte)0;
PlatformAPIs.AlphaBlend(hdcDst, x, y, image.Width,
image.Height, hdcSrc, 0, 0, image.Width,
image.Height, blendFunction);
// Required cleanup to GetHdc()
gx.ReleaseHdc(hdcDst);
// Required cleanup to GetHdc()
gxSrc.ReleaseHdc(hdcSrc);
}
}
/// <summary>
/// Fills the rectagle with gradient colors
/// </summary>
/// <param name="gx">Destination graphics</param>
/// <param name="rc">Desctination rectangle</param>
/// <param name="startColorValue">Starting color for gradient</param>
/// <param name="endColorValue">End color for gradient</param>
/// <param name="fillDirection">The direction of the gradient</param>
public static void FillGradientRectangle(this Graphics gx,
Rectangle rc, Color startColorValue, Color endColorValue,
FillDirection fillDirection)
{
GradientFill.Fill(
gx,
rc,
startColorValue,
endColorValue,
fillDirection);
}