ios - ANE、iOS 和 BitmapData
<p><p>是否有任何将位图数据传递到 iOS 并返回修改后副本的示例。我正在尝试将位图转换为 jpeg - 类似于 Windows <a href="http://blog.magicalhobo.com/2011/09/12/air-3-native-extension-imagepro" rel="noreferrer noopener nofollow">http://blog.magicalhobo.com/2011/09/12/air-3-native-extension-imagepro</a> 中的此示例cessor/但它每次都崩溃了。 </p>
<p>我很确定我做错了一些基本错误但不是 iOS/Objective C 程序员我真的只是在尝试魔法咒语,我找不到任何好的例子。任何帮助表示赞赏?</p>
<p>肖恩</p>
<p>附:以下是我的尝试:</p>
<pre><code>FREObject encodeJPEG(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[])
{
FREObject objectBitmapData = argv;
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 = ;
NSData *jpgData= UIImageJPEGRepresentation(myImage, 0.9);
FREObject objectByteArray = argv;
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;
</code></pre>
<p>}</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>最终版本 - 似乎工作正常 - 编码正常,我认为自己可以清理。</p>
<p>肖恩</p>
<pre><code>FREObject encodeJPEG( FREContext ctx, void* funcData, uint32_t argc, FREObject argv[] )
{
FREObject objectBitmapData = argv[ 0 ];
FREBitmapData2bitmapData;
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;
}
CGColorRenderingIntentrenderingIntent = kCGRenderingIntentDefault;
CGImageRef imageRef = CGImageCreate(width, height, bitsPerComponent, bitsPerPixel, bytesPerRow, colorSpaceRef, bitmapInfo, provider, NULL, NO, renderingIntent);
// make UIImage from CGImage
UIImage *myImage = ;
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;
</code></pre>
<p>}</p></p>
<p style="font-size: 20px;">关于ios - ANE、iOS 和 BitmapData,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/8524388/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/8524388/
</a>
</p>
页:
[1]