如何从字节码获取UIImage ...在iPhone代码上 [英] How to get UIImage from Byte...at IPhone code
本文介绍了如何从字节码获取UIImage ...在iPhone代码上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我通过下一个代码从UIImage获得了字节数组。
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 );
现在。我想要UIImage来自 pixelData ...帮助..
Now.. I want UIImage from "pixelData"... help..
RGBAPixel是一个结构...
->整数红色;浅绿色浅蓝色int alpha;
RGBAPixel is a struct... --> int red; int green; int blue; int alpha;
推荐答案
以下是我从上下文中获取UIImage的方法。
The following is the way I get a UIImage from context.
CGImageRef aCGImg = CGBitmapContextCreateImage(context);
UIImage *aUIImg = [UIImage imageWithCGImage:aCGImg];
CGImageRelease(aCGImg);
这篇关于如何从字节码获取UIImage ...在iPhone代码上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文