Edited at

Adobe AIRのBitmapDataをObjectiveCでUIImageにするANEなやり方

More than 5 years have passed since last update.


BitmapData2UIImage.m

FREObject bitmapData2UIImage(FREContext ctx, void* funcData, 

uint32_t argc, FREObject argv[]) {

FREObject data = argv[0];
FREBitmapData2 bitmapData;

FREAcquireBitmapData2(data, &bitmapData);

int width = bitmapData.width;
int height = bitmapData.height;
CGDataProviderRef provider = CGDataProviderCreateWithData(
NULL, bitmapData.bits32, (width * height * 4), NULL);

int bitsPerComponent = 8;
int bitsPerPixel = 32;
int bytesPerRow = 4 * width;
CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
CGBitmapInfo bitmapInfo;

if (bitmapData.hasAlpha) {
if (bitmapData.isPremultiplied) {
bitmapInfo =
kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst;
} else {
bitmapInfo =
kCGBitmapByteOrder32Little | kCGImageAlphaFirst;
}
} else {
bitmapInfo =
kCGBitmapByteOrder32Little | kCGImageAlphaNoneSkipFirst;
}

CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault;
CGImageRef imageRef = CGImageCreate(width, height,
bitsPerComponent, bitsPerPixel, bytesPerRow, colorSpaceRef,
bitmapInfo, provider, NULL, NO, renderingIntent);

UIImage *image = [UIImage imageWithCGImage:imageRef];
FREReleaseBitmapData(data);
return NULL;
}