I i need to pass an image I render in game to the Obj-C part.
The CCImage I make is working well (verified) but when I make a UIImage and attach it to the view it comes out as junk.
This is how it init my image CCImage object
this->initWithImageData((void*)img->getData(), img->getDataLen(),kFmtRawData,img->getWidth(),img->getHeight(),8)
In Obj-C, this is how I make the UIImage
@
-(BOOL)createUploadImageFromData:(const void *)data andDataLength:(size_t)dataLength andImageWidth:(size_t)width andImageHeight:(size_t)height andBitsPerComponent:(size_t)bpc andComponentsPerPixel:(size_t)cpp
{
BOOL bRet = NO;
CGColorSpaceRef rgb = CGColorSpaceCreateDeviceRGB();
do{
CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, data, dataLength, NULL);//freeBitmapBuffer);
if( ! provider ) break;
CGImageRef imageRef = CGImageCreate(width, height, bpc,
bpc * cpp,
cpp * width,
rgb,
kCGBitmapByteOrderDefault,
provider, NULL, false, kCGRenderingIntentDefault); // | kCGImageAlphaLast
if( ! imageRef ) break;
self.uploadImage = [UIImage imageWithCGImage:imageRef];
bRet = YES;
}while (0);
return bRet;
}
@
The created image ahas all the right dimensions but the data is somehow corrupt. Any tips?
Thanks