I wan to print an image on a bluetooth printer. I got some sample code by the printer manufacturer. Here is the code -
unsigned char buffer3[796]={
Try this:
CGImageRef image = [yourUIImage CGImage];
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
NSUInteger width = CGImageGetWidth(image);
NSUInteger height = CGImageGetHeight(image);
NSUInteger bytesPerPixel = 4;
NSUInteger bytesPerRow = bytesPerPixel * width;
NSUInteger bitsPerComponent = 8;
int size = height*width*bytesPerPixel;
printf("Size:%d\n",size);
unsigned char *rawData = malloc(size);
CGContextRef context = CGBitmapContextCreate(rawData,width,height,bitsPerComponent,bytesPerRow,colorSpace,kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
CGColorSpaceRelease(colorSpace);
CGContextDrawImage(context, CGRectMake(0,0,width,height),image);
CGContextRelease(context);
Now, rawData is the data you need.
Source: http://www.iphonedevsdk.com/forum/iphone-sdk-development/21806-convert-cgimage-uiimage.html
Edit: you have maxLength:796
in your code, but I'm pretty sure this depends on the particular image, you should probably replace 796
by something like sizeof(rawData)
.