如何从字节在IPhone代码得到的UIImage ...
问题描述:
,我从UIImage的字节数组明年代码..如何从字节在IPhone代码得到的UIImage ...
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);
现在..我想从UIImage的 “PixelData取出” ...帮助..
RGBAPixel是一个结构... - > int red; int green; int blue; int alpha;
答
以下是我从上下文中获取UIImage的方式。
CGImageRef aCGImg = CGBitmapContextCreateImage(context);
UIImage *aUIImg = [UIImage imageWithCGImage:aCGImg];
CGImageRelease(aCGImg);