取得的jpeg raw data轉成CCSprite
做法:
//先取得raw data, 這邊會先copy到別處,是因為我會對data做些處理
uint8_t *imageData = (uint8_t*)malloc(sizeof(uint8_t) * jpegImageSize);
memcpy(imageData, [jpegImageData bytes], jpegImageSize);
//針對jpeg就解碼
CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, imageData, jpegImageSize, NULL);
CGImageRef image = CGImageCreateWithJPEGDataProvider(provider, NULL, NO, kCGRenderingIntentDefault);
CGDataProviderRelease(provider);
//初始化貼圖,解析度用iPad
CCTexture2D * tex = [[CCTexture2D alloc] initWithCGImage:image resolutionType:kCCResolutioniPad];
free(imageData);
CGImageRelease(image);
//這樣就可以建sprite了
CCSprite *sprite = [CCSprite spriteWithTexture:tex];
參考網址:
Cocos2d screenShot
CGDataProvider Reference
JPEG Header Format
通过Quartz+Core Image读取JPEG图像的二进制位图
How exactly to make a CGImageRef from an image on disk
CCTexture2D errors in adding images
Using CGDataProviderCreateWithData callback
沒有留言:
張貼留言