Ramp Up for Windows Mobile 6#

With Windows Mobile 6.5 being complete it might be time to Ramp Up on developing for Windows Mobile.  There are 7 free courses you can take:

Level 1: Mobile Development Introduction
Level 2: Device Emulators
Level 3: Mobile Windows Forms Development
Level 4: Advanced Mobile Windows Forms Development
Level 5: SQL Server CE Introduction
Level 6: Security and Deployment
Level 7: Mobile Web Development

Remember if the above is not enough, we offer Windows Mobile developer training to get your developers up and running with developing for Windows Mobile.

There is also training available on ASP.NET, Sharepoint, Visual Studio 2008 and developer basics.  Check it out and get some free training.


Tuesday, May 19, 2009 1:16:51 PM (Eastern Daylight Time, UTC-04:00) #    Comments [0]  |  Trackback

 

Convert an Image to Grayscale with Compact Framework on Windows Mobile#

I’m working with a customer and they have a requirement to convert an image to gray scale.  Using direct pixel access method discussed here and extension methods it’s pretty straight forward.

public static Bitmap ModifyColors(this Bitmap image, double redChange, double greenChange, double blueChange)
{
    if (image == null)
        return null;
    Bitmap newBitmap = (Bitmap)image.Clone();

    int width = newBitmap.Width;
    int height = newBitmap.Height;

    unsafe
    {
        BitmapData bd = newBitmap.LockBits(new Rectangle(0, 0, newBitmap.Width, newBitmap.Height),
            ImageLockMode.ReadWrite,
            PixelFormat.Format24bppRgb);
        int sourceWidth = newBitmap.Width * System.Runtime.InteropServices.Marshal.SizeOf(typeof(PixelData));
        if (sourceWidth % 4 != 0)
            sourceWidth += (4 - (sourceWidth % 4));
        Byte* bitmapBaseByte;
        bitmapBaseByte = (Byte*)bd.Scan0.ToPointer();
        PixelData* pPixel;
        int redVal;
        int greenVal;
        int blueVal;
        for (int y = 0; y < height; y++)
        {
            pPixel = (PixelData*)(bitmapBaseByte + y * sourceWidth);
            for (int x = 0; x < width; x++)
            {
                redVal = (int)(pPixel->red * redChange) + (int)(pPixel->green * greenChange) + (int)(pPixel->blue * blueChange);
                if (redVal < 0) redVal = 0;
                if (redVal > 255) redVal = 255;
                pPixel->red = (byte)redVal;

                greenVal = (int)(pPixel->red * redChange) + (int)(pPixel->green * greenChange) + (int)(pPixel->blue * blueChange);
                if (greenVal < 0) greenVal = 0;
                if (greenVal > 255) greenVal = 255;
                pPixel->green = (byte)greenVal;

                blueVal = (int)(pPixel->red * redChange) + (int)(pPixel->green * greenChange) + (int)(pPixel->blue * blueChange);
                if (blueVal < 0) blueVal = 0;
                if (blueVal > 255) blueVal = 255;
                pPixel->blue = (byte)blueVal;

                pPixel++;

            }
        }

        newBitmap.UnlockBits(bd);
    }

    return newBitmap;
}

Basically all we are doing is getting direct access to the pixel data using a pointer and modifying the RGB values with the parameters sent by the user.  In our main code where we want to convert the image, lets say we have an image in a PictureBox that we want to convert and store the result in a new PictureBox all we have to do is call one line of code:

pictureBox2.Image = pictureBox1.Image.ToGrayScale();

Here is a sample of the input/output:

image

And you can download the source for converting an image to grayscale here


Tuesday, May 19, 2009 12:28:54 PM (Eastern Daylight Time, UTC-04:00) #    Comments [0]  |  Trackback

 

All content © 2012, Mark Arteaga
Related Sites
Archives
Sitemap
Disclaimer

Powered by: newtelligence dasBlog 1.9.7174.0

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

Send mail to the author(s) E-mail

Theme design by Jelle Druyts