Mobile Scanning Application Framework#

Back in April at the Toronto Code Camp 2009 after my Windows Mobile Developer Boot-Camp presentation I met Dan Douglas and we discussed about some Windows Mobile projects he has worked in his organization.  He recently blogged about a Mobile Scanning Framework he implemented and demonstrates one possible way to encapsulate bar code scanning input and validation of the data within a Windows Mobile application using .NET Compact Framework


Tuesday, July 21, 2009 9:43:55 PM (Eastern Daylight Time, UTC-04:00) #    Comments [0]  | 

 

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]  | 

 

Developing for Windows Mobile – Leveraging Existing .NET Code#

I’ve been getting a few emails/questions on ‘Leveraging Existing .NET Code’ section of my Platform In Your Pocket session for TechDays so just wanted to share what I’ve been sharing with those emails.

First all credits go to Daniel Moth for his Sharing Assets between Windows Mobile and Windows Desktop he did back in 2006.  Daniel now works for the Parallel Computing Platform so be sure to check out his blog for tips and check out his PDC session here.

I only spent about 15mins on leveraging existing code and is only a small fraction of what Daniel covered in his session.  I always reference his blog posts when responding to emails so I’ll do the same here. His most recent post is on Sharing Assets Between the .NET Compact Framework and the .NET Framework has all relevant links.  There is an article in MSDN Magazine article which also goes through the concepts.

If you are a .NET developer looking at writing a Windows Mobile application make sure you leverage your existing code so you can get your product to your customers faster.

Good Luck and if you have more questions feel free to contact me!


Wednesday, February 11, 2009 11:54:07 AM (Eastern Standard Time, UTC-05:00) #    Comments [0]  | 

 

Optimizing your Windows Mobile Applications#

I’ve been consulting for Windows Mobile projects for quite a few years now and know most of the techniques to optimize custom Windows Mobile software.  During my 'Platform in Your Pocket' session for TechDays Canada, I went through some optimizations tips and tricks such as using StringBuilder as opposed to string or List<T> opposed to ArrayList things that you take for granted when developing on the desktop using the .NET Framework.  On Windows Mobile it's more important because you are 'memory constrained' and can't just 'throw more RAM or CPU' in a device to make your application perform better. 

During the session I didn’t have time to cover everything to optimize your code and a common question was ‘what else can I do to optimize my code’.  Here is a page on MSDN that lists a few ways to improve the performance of you Windows Mobile app using .NET Compact Framework which should help when you are developing your software.


Tuesday, February 03, 2009 2:30:59 PM (Eastern Standard Time, UTC-05:00) #    Comments [0]  | 

 

Memory Management on Windows Mobile using .NET Compact Framework#

During my Windows Mobile developer session in Calgary for TechDays Canada surprisingly a few people wanted to know more about the memory architecture of a .NET Compact Framework application.  I didn't cover anything on that but the best reference for this if you want to learn more about it is the follow:

  1. MSDN Webcast: Microsoft .NET Compact Framework Memory Management by Chris Tacke (2006*)
  2. .NET Compact Framework Advanced Memory Management by Mike Zintel  (2004*)

These things go into a lot of the internals of the .NET Compact Framework CLR and the Windows CE memory architecture (Windows Mobile is based on Windows CE) but in my opinion are required readings if you are building Windows Mobile applications.

*Don't worry about the years they where done as it's still relevant when developing on Windows Mobile today.


Wednesday, December 10, 2008 3:25:05 PM (Eastern Standard Time, UTC-05:00) #    Comments [0]  | 

 

All content © 2010, 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