Is much time i don't help iOS coders to do some AGK<->OBJ C porting.
Now i wanna give you this trick
Remember to
#import <UIKit/UIKit.h>
To use it write:
int _new_image = CreateImageFromUIImage([UIImage imageNamed:@"test.png"]);
int CreateImageFromUIImage (UIImage *_im){
CGImageRef cRef = CGImageRetain(_im.CGImage);
NSData* pixelData = (NSData*) CGDataProviderCopyData(CGImageGetDataProvider(cRef));
unsigned char* rawData = (unsigned char *)[pixelData bytes];
int _mem = agk::CreateMemblock(12 + [pixelData length]);
agk::SetMemblockByte(_mem, 0, (int)_im.size.width);
agk::SetMemblockByte(_mem, 4, (int)_im.size.height);
agk::SetMemblockByte(_mem, 8, 16);
for(int i = 0; i < [pixelData length]; i += 4){
int pos = i + 12;
agk::SetMemblockByte(_mem, pos, rawData[i]);
agk::SetMemblockByte(_mem, pos + 1, rawData[i + 1]);
agk::SetMemblockByte(_mem, pos + 2, rawData[i + 2]);
agk::SetMemblockByte(_mem, pos + 3, rawData[i + 3]);
//NSLog(@"I -> %i -- R : %i - G : %i - B : %i - A : %i", i, rawData[i], rawData[i]+1, rawData[i]+2, rawData[i]+3);
}
free(rawData);
int id_image = agk::CreateImageFromMemblock(_mem);
agk::DeleteMemblock(_mem);
return id_image;
}
If you have questions, don't hesitate to ask!!
Enjoy!!
Long life to Steve!