QRCode for .NET Compact Framework

In my previous post I left a hint on a new project I was working on which was this image:

After reading about Windows Live Barcode and seeing it was not available  at barcode.ideas.live.com I decided to look around to see if there was something available for .NET CF to create an application to decode these images on a Windows Mobile device using the built in camera.  Nothing was available except this JavaME implementation here.  So I ported that code to C# and now we have QRCode Library for .NET Compact Framework.

What is a QR Code?  Well, it is a two-dimensional barcode that should be decoded at high speeds.  QR stands for ‘Quick Response’.

The image above was my test image (generated here) and here is the result running it on a Windows Mobile 5 device:


So my question was answered and it does work.  Next test was testing with an image using the CameraCaptureDialog to see if the library can decode an image taken with a device camera.  Here is the image:


And here is the result:


Although this was pretty exciting to be able to decode an image taken by the camera on the device (yes I think that’s exciting 🙂 it did take me about 5-7 tries before the image was actually decoded.  It wasn’t until I changed the JPG Quality to ‘SuperFine’ was the image decoded.  So IMO for the regular user I don’t think it’s ready for ‘prime time’.  Now my camera is only 1.3 mega pixels but new devices with 3.0 mega pixel cameras are now out which should help improve the image quality and the decoding success rate (time to upgrade my device!).

Another exciting part was decoding the image was pretty fast after the change I made I discussed in my previous post

So if you are interested in the project you can find all details here.  It is open source and we have added the source to our SVN Repository (main page is not updated but you can browse the source code).

BTW … if you want to generate an QR Code using a web service check out Richard Jones post here.

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 324×324 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 324×324 image was 0.5s):

BitmapData bd = image.LockBits(new Rectangle(0, 0, image.Width, image.Height),
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);


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: