LoginSignup
9
9

More than 5 years have passed since last update.

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

Last updated at Posted at 2014-08-16
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;
}
9
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
9