Damnit. Got everything working and then got errors during the first tests:
2010-10-19 18:34:14.969 Cooking Companion[1369:207] AGPSessionBroadcast failed (801c0001)
It would appear that I’m limited to 95kB. Sadly I am trying to send:
(gdb) print (NSUInteger)[data length] $4 = 387339
I would expect that 381000 bytes of that are my UIImage data. So I have a few choices. Firstly I’m going to stop storing full sized images but limit them to a more conservative 640 pixels tops. This seems reasonable for the iPhone 4’s 960×640 and the iPad’s 1024×768 resolution. So that restricts it to:
(gdb) print (NSUInteger)[data length] $5 = 895035
Right. Odd isn’t it? Run my images through this function to limit the size:
CGSize size = selectedImage.size;
CGFloat ratio = 0;
if (size.width > size.height) {
ratio = 640.0 / size.width;
} else {
ratio = 640.0 / size.height;
}
CGRect rect = CGRectMake(0.0, 0.0, ratio * size.width, ratio * size.height);
UIGraphicsBeginImageContext(rect.size);
[selectedImage drawInRect:rect];
recipe.photo = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
And they get much larger. A quick test using an empty view based application with a jpeg from my digital camera:
- (void)viewDidLoad {
[super viewDidLoad];
UIImage *jpeg = [UIImage imageNamed:@"P1040367.jpg"];
NSData *original = UIImagePNGRepresentation(jpeg);
CGSize size = jpeg.size;
CGFloat ratio = 0;
if (size.width > size.height) {
ratio = 640.0 / size.width;
} else {
ratio = 640.0 / size.height;
}
CGRect rect = CGRectMake(0.0, 0.0, ratio * size.width, ratio * size.height);
UIGraphicsBeginImageContext(rect.size);
[jpeg drawInRect:rect];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData *resized = UIImagePNGRepresentation(image);
NSLog(@"Finito");
}
From debugging:
(gdb) print (CGSize)[jpeg size]
$2 = {
width = 2448,
height = 3264
}
(gdb) print (CGSize)[image size]
$3 = {
width = 480,
height = 640
}
(gdb)
So it gets resized. What about the data length?
(gdb) print (NSUInteger)[original length] $4 = 10572117 (gdb) print (NSUInteger)[resized length] $5 = 639538
What’s interesting here is that the original jpeg is only 2.4 MB yet my NSData representation is 10MB. Not a good thing to transmit, it also makes me think the images I was using earlier were small and I was unwittingly making them much larger.
One Response to Should have read the Gamekit docs.