Bitmap Pixel Access Using Compact Framework#

I've been working on a new open source project this past week and had a requirement to get ARGB value of every pixel in the image.  I thought 'OK easy, just use Bitmap.GetPixel()'!  At first I was using small images so there was not a problem, but as the size of the image increased, the performance of the application just dropped!

After a little bit of digging around I found the answer right under my nose!  Rob Miles recently wrote an article on Image Manipulation in Windows Mobile 5.0 for the OpenNETCF Community site.  The section that stood out to me was 'Speeding up Bitmap Access'.  I took the techniques he showed in the article and implemented them in my code.  The result was an average savings of 11.5s to grab the pixel ARGB values.

Here is the original code (average for time for a 324x324 image was 12s):

for (int y = 0; y < height; y++)
{
    for (int x = 0; x < width; x++)
    {
        intImage[x][y] = image.GetPixel(x, y).ToArgb();
    }
}

And here is the new code (average for time for a 324x324 image was 0.5s):

unsafe
{
    BitmapData bd = image.LockBits(new Rectangle(0, 0, image.Width, image.Height),
        ImageLockMode.ReadOnly,
        PixelFormat.Format24bppRgb);
    int sourceWidth = image.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;
    for (int y = 0; y < height; y++)
    {
        pPixel = (PixelData*)(bitmapBaseByte + y * sourceWidth);
        for (int x = 0; x < width; x++)
        {
            intImage[x][y] = (int)((0xff << 0x18) | (pPixel->red << 0x10) | (pPixel->green << 8) | pPixel->blue);
            pPixel++;
        }
    }

    image.UnlockBits(bd);
}

By using unsafe block and directly accessing the bitmap data in memory we save a huge 11.5s on average.  If you want a more detailed explanation on how the code works read the article

For those interested here is the image I was testing with:

9/29/2007 4:19:45 AM (Eastern Daylight Time, UTC-04:00) #    Comments [0]  |  Trackback

 

Sharing WISP Lite Ink with the Desktop#

I just finished writing a new article on sharing ink data created on a windows Mobile 6 device using the Mobile Ink Library with a custom desktop application and OneNote 2007.

If you have used the Mobile Ink Library then you'll probably want to know that I have made changes to the class library but I have marked methods obsolete to keep backward compatibility.  I've also posted the 'technical overview' of the Mobile Ink Library which is basically the same as the previous blog posts on WISP Lite and Mobile Ink Library but updated with the new updates.

Here are some screen shots on sharing ink with a custom desktop application:

And here are some screen shots on sharing ink data with OneNote 2007:

I have yet to update the SVN Repository but will update that in a couple of days.  I have update the installable source located here

I'm done inking for a while but the source is in a good state to be used in projects IMO.  I have been working on another open source project that will hopefully be released in the coming days plus a new commercial product so stay tuned!

9/29/2007 1:02:01 AM (Eastern Daylight Time, UTC-04:00) #    Comments [0]  |  Trackback

 

Recent Product Releases#

We recently released two new products for Windows Mobile and Windows CE developers. 

The first one is TaskManCF which runs on Windows Mobile (no SmartPhone) and Windows CE devices.  It allows you to view all applications running, processes, threads etc.  Here is a screen shot of the product running on a WM5 device.

The second product we released is a Media Player Control for Windows CE devices.  If you are a Compact Framework developer and want to add video media directly into your application then check out the this control.  It allows you to add the video window directly onto a form so no loading up Media Player and hacking it to play video.  We created a 'Video Kiosk' sample that highlights this feature.  Here are some screen shots.

Main Screen:

 Main

Video Playing:

 RushHour3

The Media Player Control for Windows CE is only for Windows CE devices (as the name implies) and not supported on Windows Mobile.  We are working on a version for Windows Mobile devices so stay tuned...

9/21/2007 2:14:45 PM (Eastern Daylight Time, UTC-04:00) #    Comments [0]  |  Trackback

 

Outlook Mobile Style Textbox#

There was a question on how to create a Textbox similar in style to Outlook Mobile contacts textbox shown below (single line shown for inputs).

Contacts

So to accomplish this I wrote a quick custom control that included a textbox internally and the control was on pixel higher than the textbox and set the Textbox.BorderStyle to None. On the OnPaint method of the custom control I just call Graphics.Clear() to draw a black line since only one pixel height is visible.

Here is the source.  It still requires a lot of work but it's a good start and it answers the original question.

public class OutlookMobileTextBox : Control
{
    private TextBox m_textBox;

    public OutlookMobileTextBox()
    {
        m_textBox = new TextBox();
        m_textBox.Location = new System.Drawing.Point(48, 107);
        m_textBox.BorderStyle = BorderStyle.None;
        m_textBox.Size = new System.Drawing.Size(100, 21);
        Controls.Add(m_textBox);
    }

   
    protected override void OnResize(EventArgs e)
    {
        base.OnResize(e);
        m_textBox.Bounds = new Rectangle(0, 0, this.Width, m_textBox.Height);
        base.Height = m_textBox.Height + 1;

    }
    protected override void OnPaint(PaintEventArgs e)
    {
        e.Graphics.Clear(Color.Black);
    }
    protected override void OnPaintBackground(PaintEventArgs e)
    {
    }

    public override string Text
    {
        get
        {
            return this.m_textBox.Text;
        }
        set
        {
            this.m_textBox.Text = value;
        }
    }
} 

And here is what it looks like on a device:

 OutlookMobileTextbox

9/13/2007 5:32:19 PM (Eastern Daylight Time, UTC-04:00) #    Comments [0]  |  Trackback

 

DemoCampToronto14#

DemoCampToronto14 is happening this Sept 17 2007 and I'll be there.  What is DemoCamp? It's a variation of the unconference style of event where community members share what they've been working on, demo their products and meet others.  I won't be presenting anything but will be attending (OpenNETCF has also helped sponsor the event).  It's a great place to meet the people and see what cool things people are working on!  If you are in the Toronto area and attending (registration has sold out) drop by and say hi!  If we have never met here's what I look like :).

9/12/2007 4:55:57 PM (Eastern Daylight Time, UTC-04:00) #    Comments [0]  |  Trackback

 

All content © 2008, Mark Arteaga
Related Sites
Archives
Sitemap
Blogroll OPML
Disclaimer

Powered by: newtelligence dasBlog 1.8.5223.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