gpt4 book ai didi

ios - ANE、iOS 和位图数据

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:17:43 24 4
gpt4 key购买 nike

是否有任何将位图数据传递到 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 和位图数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8524388/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com