如何从头开始创建UIImage。具体来说,我想创建一个大小为320x50的UIImage。然后,我希望能够在该图像上绘制特定颜色的多边形。创建特定大小的UIImage
4
A
回答
5
这里的结果创建UIImage
是你stitch picture in iphone
和基础上我的经验一个答案,我可以给你一些注意事项:
Propotional规模
- (UIImage *)scaleImage:(UIImage *)image toScale:(float)scaleSize { UIGraphicsBeginImageContext(CGSizeMake(image.size.width*scaleSize,image.size.height*scaleSize); [image drawInRect:CGRectMake(0, 0, image.size.width * scaleSize, image.size.height *scaleSize)]; UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return scaledImage; }
调整大小
- (UIImage *)reSizeImage:(UIImage *)image toSize:(CGSize)reSize { UIGraphicsBeginImageContext(CGSizeMake(reSize.width, reSize.height)); [image drawInRect:CGRectMake(0, 0, reSize.width, reSize.height)]; UIImage *reSizeImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return reSizeImage; }
处理特定视图
您哈瓦导入QuzrtzCore.framework第一
-(UIImage*)captureView:(UIView *)theView { CGRect rect = theView.frame; UIGraphicsBeginImageContext(rect.size); CGContextRef context = UIGraphicsGetCurrentContext(); [theView.layer renderInContext:context]; UIImage *img = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return img; }
处理一系列表格图像
CGRect captureRect = yourRect CGRect viewRect = self.view.frame; UIImage *viewImg; UIImage *captureImg; UIGraphicsBeginImageContext(viewRect.size); CGContextRef context = UIGraphicsGetCurrentContext(); [self.view.layer renderInContext:context]; viewImg = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); captureImg = [UIImage imageWithCGImage:CGImageCreateWithImageInRect(viewImg.CGImage, captureRect)];
保存图像
保存在应用
NSString *path = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"image.png"]; [UIImagePNGRepresentation(image) writeToFile:path atomically:YES];
保存在相册
CGImageRef screen = UIGetScreenImage(); UIImage* image = [UIImage imageWithCGImage:screen]; CGImageRelease(screen); UIImageWriteToSavedPhotosAlbum(image, self, nil, nil);
+0
感谢您的广泛响应,但我不确定这些东西的意思,例如“处理范围表单图像”......我可以使用哪一个简单地做一些像UIImage * newImage = [oldImage drawPolygonOnOldImage :多边形]; – CodeGuy 2012-01-16 19:57:24
2
您可以:
- 使用颜色/像素/尺寸创建
CGBitmapContext
/等你将需要。 - 使用上下文或直接操作像素。
- 使用
CGBitmapContextCreateImage
+1
你可以展示如何做到这一点的具体细节? – CodeGuy 2012-01-17 04:09:47
相关问题
- 1. 创建特定大小
- 2. 创建特定大小的文件
- 3. 调整大小的UIImage创建CGImageContext在模拟器
- 4. 在python中创建特定大小的文件
- 5. 创建特定大小的Java变量(字符串)
- 6. 创建特定大小的绘图窗口
- 7. 如何用特定大小的Java创建文件(不稀疏)
- 8. UIImageView中的UIImage大小
- 9. UIImage UIImage小+中+大如苹果邮件
- 10. C#创建给定大小的表格
- 11. 猪 - 创建给定大小的组
- 12. 创建固定大小的堆栈
- 13. 如何减少UIImage大小...?
- 14. UIImageJPEGRepresentation增加UIImage大小
- 15. 从CIImage创建UIImage
- 16. 从MKMapView创建UIImage
- 17. 从UIImage创建MSSticker
- 18. 从UILabel创建UIImage?
- 19. 将UIImage的大小更改为所需的大小
- 20. UIImage的自我大小的UITableViewCell拉伸
- 21. UIImage的NSData的有没有大小
- 22. 在终端(OSX)中创建大量指定大小的文件?
- 23. 为UIPrintInteractionController调整UIImage的大小
- 24. 在UIImageView中调整UIImage的大小
- 25. UIImage:大小奇怪的问题
- 26. uiimage报告无效的大小
- 27. 线程安全的UIImage调整大小?
- 28. 如何获取UIImage的大小(KB)
- 29. EXC_BAD_ACCESS访问UIImage的大小属性
- 30. 如何创建具有特定大小的SQL Server地理多边形?
您可以使用Quartz Graphics轻松绘制图像。如果我理解正确,你只是想在图像上绘制一些东西?那么在Quartz Graphics中,您可以在绘制图像后完成Quartz Graphics绘制的绘制图像的顶部。你可能应该看看那个;) – 2012-01-16 08:37:34