Click here to Skip to main content
15,896,063 members
Articles / Mobile Apps

Windows Mobile Password Safe

Rate me:
Please Sign up or sign in to vote.
4.87/5 (58 votes)
12 Jan 2009CPOL16 min read 161.5K   3.1K   139  
A password safe with a touch screen UI introducing Fluid Controls.
using System;

using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace Fluid.Drawing.GdiPlus
{
    public static class ColorConverter
    {
        /// <summary>
        /// Gets the Color as a result of a background color overlapped by a color with a transparency.
        /// </summary>
        /// <param name="backColor">The background color.</param>
        /// <param name="blendColor">The overlapped color.</param>
        /// <param name="alpha">The alphablend value between 0 and 255.</param>
        /// <returns>A combinded color.</returns>
        public static Color AlphaBlendColor(Color backColor, Color blendColor, int alpha)
        {
            int r = Blend(blendColor.R, backColor.R, alpha);
            int g = Blend(blendColor.G, backColor.G, alpha);
            int b = Blend(blendColor.B, backColor.B, alpha);

            return Color.FromArgb(r, g, b);
        }


        private static int Blend(int value1, int value2, int alpha)
        {
            int d = value1 - value2;
            return (d * alpha) / 255 + value2;
        }

        /// <summary>
        /// Converts a 24 or less bit color to a 32 bit color with a alpha channel of 255 (opaque).
        /// </summary>
        /// <param name="color">The color without alpha channel.</param>
        /// <returns>The same color, but with alpha channel set to 255.</returns>
        public static Color OpaqueColor(Color color)
        {
            int argb = color.ToArgb() | (0xff << 24);
            return Color.FromArgb(argb);
        }

        /// <summary>
        /// Converts a 24 or less bit color to a 32 bit color with a specific alpha channel.
        /// </summary>
        /// <param name="c">The rgb color to convert.</param>
        /// <param name="alpha">The alpha value for the color.</param>
        /// <returns>The new color with alpha channel.</returns>
        public static Color AlphaColor(Color c, int alpha)
        {
            uint ualpha = (uint)alpha;
            ualpha = ualpha << 24;
            int mask = (int)ualpha;
            int v = c.B | (c.G << 8) | (c.R << 0x10) | mask;

            Color result = Color.FromArgb(v);
            return result;

        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Germany Germany
MCPD
Enterprise Application Developer 3.5
Windows Developer 3.5
.ASP.NET Developer 3.5
.NET 2.0 Windows Developer
.NET 2.0 Web Developer
.NET 2.0 Enterprise Application Developer


MCTS
.NET 3.5 Windows Forms Applications
.NET 3.5 ASP.NET Applications
.NET 3.5, ADO.NET Application Development
.NET 3.5 WCF
.NET 3.5 WPF
.NET 3.5 WF
Microsoft SQL Server 2008, Database Development
.NET 2.0 Windows Applications
.NET 2.0 Web Applications
.NET 2.0 Distributed Applications
SQL Server 2005
Sharepoint Services 3.0 Application Development
Windows Vista Client Configuration

Comments and Discussions