Mix alpha to color - CSharp System.Drawing

CSharp examples for System.Drawing:Color

Description

Mix alpha to color

Demo Code

// Copyright (C) Microsoft Corporation. All rights reserved.
using System.Text;
using System.Collections.Generic;
using System;/*from   w w w  .j  a  v a2 s .  c om*/
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

public class Main{
        /// <summary>
        /// Mix alpha to color
        /// </summary>
        /// <param name="col">Color</param>
        /// <param name="newAlpha">New alpha</param>
        /// <returns>Color</returns>
        public static Color MixAlphaToColor(Color col, float newAlpha)
        {
            if (newAlpha < 0)
                newAlpha = 0;
            if (newAlpha > 1)
                newAlpha = 1;
            return new Color(
                (byte)(col.R * newAlpha),
                (byte)(col.G * newAlpha),
                (byte)(col.B * newAlpha),
                (byte)(newAlpha * 255.0f));
        }
}

Related Tutorials