如何从内存中的像素获取UIImage

时间:2013-05-21 09:13:23

标签: ios objective-c uiimage

我在记忆中有一张照片,但我如何获得UIImage?

我尝试了以下两种方法并使用“UIImageWriteToSavedPhotosAlbum(myImage,self,nil,nil);”将图像保存到我的相册,但它无法正常工作。我该如何解决这个问题?

首先:

NSData *imageData = [[NSData alloc]initWithBytes:texture->data  length:picSize];
UIImage* myImage = [ [ UIImage alloc ]initWithData:imageData ];

第二

CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, texture->data, texture->image_size.width * texture->image_size.height * texture->bytesPerPixel, NULL);
// prep the ingredients
int bitsPerComponent = 8;
int bitsPerPixel = 32;
int bytesPerRow = 4 * 320;
CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault;
CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault;
// make the cgimage
CGImageRef imageRef = CGImageCreate(320, 480, bitsPerComponent, bitsPerPixel, bytesPerRow, colorSpaceRef, bitmapInfo, provider, NULL, NO, renderingIntent);
UIImage *myImage = [UIImage imageWithCGImage:imageRef];

0 个答案:

没有答案
相关问题