How to get UIImage from Byte…at IPhone code

我的梦境 提交于 2020-02-02 16:12:51

问题


I got byte array from UIImage by next code..

context = CGBitmapContextCreate(    (void*) pixelData,
                                inImage.size.width,
                                inImage.size.height,
                                RGBA_8_BIT,
                                bytesPerRow,
                                colorSpace,
                                kCGImageAlphaPremultipliedLast );

//  Make sure we have our context   
if ( ! context )    
{
    free( pixelData );
    NSLog( @"Context not created!" );
}


//  Draw the image to the bitmap context.   
//  The memory allocated for the context for rendering will then contain the raw image pixelData in the specified color space.
CGRect rect = {     { 0 , 0 }, { inImage.size.width, inImage.size.height }        };
CGContextDrawImage( context, rect, inImage.CGImage );

// Now we can get a pointer to the image pixelData associated with the bitmap context.
pixelData = (RGBAPixel*) CGBitmapContextGetData( context );

Now.. I want UIImage from "pixelData"... help..

RGBAPixel is a struct... --> int red; int green; int blue; int alpha;


回答1:


The following is the way I get a UIImage from context.

CGImageRef aCGImg = CGBitmapContextCreateImage(context);
UIImage *aUIImg = [UIImage imageWithCGImage:aCGImg];
CGImageRelease(aCGImg);


来源:https://stackoverflow.com/questions/4372809/how-to-get-uiimage-from-byte-at-iphone-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!