iphone - UIImage 到 BitmapContext

标签 iphone ios xcode ipad ipod

我想将一个简单的 UIImage 转换为 BitmapContext,但找不到任何将 UIImage 转换为 BitmapContext 的教程。请告诉我该怎么做?

谢谢!

最佳答案

可能这段代码对你有帮助

CGSize newSize = CGSizeMake(320, 400);
UIGraphicsBeginImageContext( newSize );

[imageView.image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];



UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

NSData * data = UIImagePNGRepresentation(newImage);
[data writeToFile:@"foo.png" atomically:YES];


 UIImageWriteToSavedPhotosAlbum(newImage, nil, nil, nil);///save image in phone

OR For Bitmap.

CGContextRelease(context);
context = CGBitmapContextCreate (NULL,                                                     
                                image.size.width,
                                image.size.height,
                                8,    // bits per component
                                bitmapBytesPerRow,
                                colorSpace,
                                kCGImageAlphaLast
                                );
CGColorSpaceRelease( colorSpace );                                                                      

CGContextDrawImage(context, CGRectMake(0, 0, image.size.width, image.size.height), image.CGImage);
pixelData = CGBitmapContextGetData(context);

关于iphone - UIImage 到 BitmapContext,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11789528/

相关文章:

ios - 为什么 Xcode 4.2 在将鼠标悬停在变量上时不在 Debug模式下显示变量值?

ios - 如何将字幕从 uitableview 推送到详细 View Controller

iphone - 我可以为 UIKeyboard 着色(黑色)吗?如果是这样,如何?

iphone - 如何更改 iOS 项目以完全不使用 nib,而只使用 Objective-C 代码?

iphone - 如何在 Photos.app 中创建 iPhone "photofolder"

ios - 扩展 SKAction 以覆盖 timingMode

ios - [context assignObject : toPersistentStore ] do? 是什么

ios - NSURLSessionTask 身份验证挑战完成处理程序和 NSURLAuthenticationChallenge 客户端

xcode - 使用 react-native-safari-view 时,iOS URL 类型不适用于 React Native

ios - 无法在iPhone上模拟应用程序