Click here to Skip to main content
6,595,444 members and growing! (16,766 online)
Email Password   helpLost your password?
Platforms, Frameworks & Libraries » Mobile Development » Dialogs and Windows     Intermediate License: The Code Project Open License (CPOL)

A Color Dialog for Windows Mobile 5

By Kai Sevelin

A color dialog using alpha blending for pocket pc.
C# 2.0, .NET CF, WinMobile5, GDI+, Dev
Posted:27 Nov 2008
Views:6,639
Bookmarked:11 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
4 votes for this article.
Popularity: 2.34 Rating: 3.89 out of 5

1

2
2 votes, 50.0%
3
1 vote, 25.0%
4
1 vote, 25.0%
5

Introduction

I was going to make a color dialog for one of my professional projects, but the feature was not needed and I only got a glimpse of how I thought a color dialog should be. I wanted a hue-based palette and wondered why I couldn't find any decent free color dialog on the net. Maybe it was because I didn't Google enough or maybe it was because of the inherent complexity in transparence on the mobile platform.

I found some clues however:

Alphablending came from Chris Lortons excellent blog.

The HSL-class is objectified from the sample code made by the Irish people at geekymonkey. I was astounded to get different results from different HSL-RGB converters. This one did the work.

The color dialog is not perfect. There are still some subtle hue slides (probably because of the limited color range on a mobile when you use the palette). Also, there may be other bugs and the graphic design could have been better (not my strongest side), but it should be a good starting point. It is made for 240 * 300 in resolution and some control position values are hardcoded when you move to a horizontal view. (I would have liked a view-panel where you could have moved and arranged controls depending on resolution and orientation). So, that was for getting my back free... ;)

Using the Code

You start the dialog from the test form. It exposes the public properties (caption, frontcolor and behindcolor) and let's you start the dialog.

In the dialog you can change color by clicking on the big hue-palette, by clicking on the RGB stripe, or the monochromic stripe, or by changing value in the RGB boxes. The front and behind color can be swapped by clicking on the corresponding controls in the dialog.

Color input from the palette and the stripes are made by simple GetPixel calls. The palette is made up by getting the current hue from the RGB value of the current color. When we have that we overlay it with an image combined from a horizontal white to transparent, and a vertical black to transparent. Getting color from the palette should, in theory, not change the hue.

private void Picker_Paint(object sender, PaintEventArgs e)
{
    if (m_backBuffer != null)
    {
        using (Graphics g = Graphics.FromImage(m_backBuffer))
        {

            g.Clear(this.BackColor);
            IntPtr hdcDest = g.GetHdc();
            if (m_isFore)
            {
                m_hsl.ColorValue = m_FrontColor;
            }
            else
            {
                m_hsl.ColorValue = m_BehindColor;
            }
            m_hsl.Saturation = 1;
            m_hsl.Level = 0.5;
            g.FillRectangle(new SolidBrush(m_hsl.ColorValue), m_paletteRectangle);

            Rectangle plotRect = new Rectangle(m_paletteRectangle.X,
                m_paletteRectangle.Y, m_paletteRectangle.Width + m_paletteRectangle.X,
                m_paletteRectangle.Height + m_paletteRectangle.Y);
            m_imagingImage.Draw(hdcDest, ref plotRect, IntPtr.Zero);
            g.ReleaseHdc(hdcDest);
        }
        e.Graphics.DrawImage(m_backBuffer, 0, 0);
    }
    else
        e.Graphics.Clear(this.BackColor);
    frontPictureBox.BackColor = m_FrontColor;
    backPictureBox.BackColor = m_BehindColor;
}

Overlaying the image is done in the Picker_Paint, declarations of functions in IImagingFactory and HSL conversion in the file conveniently called HSL.

History

2008-11-25 First version released.

License

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

About the Author

Kai Sevelin


Member
Currently employed at Know it, Stockholm, Sweden working with mobile solutions.
Occupation: Software Developer (Senior)
Company: Know It
Location: Sweden Sweden

Other popular Mobile Development articles:

  • Writing Your Own GPS Applications: Part 2
    In part two of the series, the author of "GPS.NET" teaches developers how to write GPS applications suitable for the real world by mastering GPS precision concepts. Source code includes a working NMEA interpreter and sample high-precision application in C# and VB.NET.
  • Writing Your Own GPS Applications: Part I
    What is it that GPS applications need to be good enough to use for in-car navigation? Also, how does the process of interpreting GPS data actually work? In this three-part series, I will cover both topics and give you the skills you need to write a commercial-grade GPS application.
  • Learn How to Find GPS Location on Any SmartPhone, and Then Make it Relevant
    A step by step tutorial for getting GPS from any SmartPhone, even without GPS built in, and then making location useful.
  • iPhone UI in Windows Mobile
    It's an interface that works with transparency effects. As a sample I used an interface just like the iPhone one. In this tutorial I am explaining how simple is working with transparency on Windows Mobile.
  • Pocket 1945 - A C# .NET CF Shooter
    An article on Pocket PC game development
Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 1 of 1 (Total in Forum: 1) (Refresh)FirstPrevNext
Generalhey PinmemberIan xie21:17 18 May '09  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 27 Nov 2008
Editor: Sean Ewington
Copyright 2008 by Kai Sevelin
Everything else Copyright © CodeProject, 1999-2009
Web12 | Advertise on the Code Project