Showing posts with label iPhone. Show all posts
Showing posts with label iPhone. Show all posts

September 18, 2010

Geo Rally for the iPhone

Geo RallyMy side project, Durbinware, released our first iPhone app, Geo Rally, to Apple's App Store back in May. It allows users to create, share and challenge timed point-to-point treasure hunts. If you've seen the movies Rat Race, or Midnight Madness you'll understand the basic concept. The first point, or starting line, is revealed at the beginning of the challenge and then each consecutive waypoint requires users to solve text-based clues or riddles to proceed. Solving a clue and arriving at the next location triggers another clue and so on until the user arrives at the last point, or finish line. Different users can compete against the same course, or Rally, and the app will optionally tweet race completion times for bragging rights. It has the potential to facilitate a great team building experience among youth groups, friends or co-workers. If this MonoTouch based app sounds interesting to you then by all means please download it.

I had a great time working on Geo Rally and was very thankful for MonoTouch. Coming from a .NET background I was a little overwhelmed at the prospect of learning a new language (Objective C) and iOS's multitude of supporting core APIs. MonoTouch eliminated one of these roadblocks so I could hit the ground running in a familiar language and branch out into unknown APIs as needed. In the end I believe this made me more productive. And now, coupled with MonoDroid and Windows Phone 7, there are even more options for code reuse (everything but the UI). It's a good time to be a C# developer!

October 14, 2009

Reading RGB Info from Images on the iPhone using MonoTouch

MonoTouch is an intriguing new software development kit from Novell. It utilizes the open source Mono project to allow developers to write code in C# that can then be statically compiled into native iPhone applications and deployed to devices or even to the App Store. A free evaluation version is available if the product interests you.



I downloaded the evaluation version and decided to take this new development kit for a spin by using it to read RGB color information from all pixels in an image saved on the device. I ended up creating a CGBitmapContext to do this and then marshaling the results into a byte array. Please see the code below for more details:

//_selectedImage refers to the UIImage object of interest
int width = _selectedImage.CGImage.Width;
int height = _selectedImage.CGImage.Height;
//4 color settings for every pixel (RGBA)
int pixelDataCount = width * height * 4;
IntPtr data = Marshal.AllocHGlobal(pixelDataCount);
int bitsPerComponent = 8;
int bytesPerPixel = 4;
int bytesPerRow = bytesPerPixel * width;
//Draw image to an RGB bitmap context
CGBitmapContext imgContext = new CGBitmapContext(data,
width, height, bitsPerComponent, bytesPerRow,
CGColorSpace.CreateDeviceRGB(), CGImageAlphaInfo.PremultipliedLast);
imgContext.DrawImage(new RectangleF(0.0F, 0.0F, width, height),
_selectedImage.CGImage);
byte[] pixelData = new byte[pixelDataCount];
Marshal.Copy(data, pixelData, 0, pixelDataCount);

//Milk the color settings for each pixel in the image
int red;
int green;
int blue;
int currentPixelIndex = 0;
for (int countHeight = 0; countHeight < height; countHeight++)
{
for (int countWidth = 0; countWidth < width; countWidth++)
{
red = pixelData[currentPixelIndex];
currentPixelIndex++;
green = pixelData[currentPixelIndex];
currentPixelIndex++;
blue = pixelData[currentPixelIndex];
currentPixelIndex++;

//Currently ignoring the alpha byte
currentPixelIndex++;

//Probably will want to Cache RGB values here for later use
}
}