是否有任何将位图数据传递到 iOS 并返回修改后副本的示例。我正在尝试将位图转换为 jpeg - 类似于 Windows http://blog.magicalhobo.com/2011/09/12/air-3-native-extension-imagepro 中的此示例cessor/但它每次都崩溃了。
我很确定我做错了一些基本错误但不是 iOS/Objective C 程序员我真的只是在尝试魔法咒语,我找不到任何好的例子。任何帮助表示赞赏?
肖恩
附:以下是我的尝试:
FREObject encodeJPEG(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[])
{
FREObject objectBitmapData = argv[0];
FREBitmapData bitmapData;
FREAcquireBitmapData(objectBitmapData, &bitmapData);
int width = bitmapData.width;
int height = bitmapData.height;
int stride = bitmapData.lineStride32 * 4;
uint32_t* input = bitmapData.bits32;
FREReleaseBitmapData(objectBitmapData);
UIImage *myImage = [UIImage imageWithData:input];
NSData *jpgData = UIImageJPEGRepresentation(myImage, 0.9);
FREObject objectByteArray = argv[1];
FREByteArray byteArray;
FREObject length;
FRENewObjectFromUint32(jpgData.length, &length);
FRESetObjectProperty(objectByteArray, (const uint8_t*) "length", length, NULL);
FREAcquireByteArray(objectByteArray, &byteArray);
memcpy(byteArray.bytes, jpgData.bytes, jpgData.length);
FREReleaseByteArray(objectByteArray);
return NULL;
}
最终版本 - 似乎工作正常 - 编码正常,我认为自己可以清理。
肖恩
FREObject encodeJPEG( FREContext ctx, void* funcData, uint32_t argc, FREObject argv[] )
{
FREObject objectBitmapData = argv[ 0 ];
FREBitmapData2 bitmapData;
FREAcquireBitmapData2( objectBitmapData, &bitmapData );
int width = bitmapData.width;
int height = bitmapData.height;
int stride = bitmapData.lineStride32 * 4;
uint32_t* input = bitmapData.bits32;
// make data provider from buffer
CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, bitmapData.bits32, (width * height * 4), NULL);
// set up for CGImage creation
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);
// make UIImage from CGImage
UIImage *myImage = [UIImage imageWithCGImage:imageRef];
NSData* jpgData = UIImageJPEGRepresentation( myImage, 0.9 );
FREReleaseBitmapData( objectBitmapData );
FREObject objectByteArray = argv[ 1 ];
FREByteArray byteArray;
FREObject length;
FRENewObjectFromUint32( jpgData.length, &length );
FRESetObjectProperty( objectByteArray, ( const uint8_t* ) "length", length, NULL );
FREAcquireByteArray( objectByteArray, &byteArray );
memcpy( byteArray.bytes, jpgData.bytes, jpgData.length );
FREReleaseByteArray( objectByteArray );
// release bits
CGColorSpaceRelease(colorSpaceRef);
CGImageRelease(imageRef);
CGDataProviderRelease(provider);
return NULL;
}
关于ios - ANE、iOS 和 BitmapData,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8524388/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |