草庐IT

ios - 如何将从 CGImageRef 创建的 UIImage 对象转换为原始数据并再次转换回来

假设您从一个UIImage开始,您希望裁剪它。最常见的方法是使用CGImageCreateWithImageInRect获取CGImageRef并从中创建一个新图像,如下所示:CGRectcropRect=CGRectMake(x*width,y*height,width,height);CGImageRefimageRef=CGImageCreateWithImageInRect([imageCGImage],cropRect);UIImage*croppedImage=[UIImageimageWithCGImage:imageRef];现在假设您稍后需要将此UIImage转换为N

ios - 当动画 UIImage 被分配两次时,UITableViewCell 中的 UIImageView 没有动画

我正在尝试在UITableViewCell的imageView中显示动画UIImage。动画图像在第一次分配后显示,但不会在每次进一步尝试时显示。这是TableViewController的代码:#import"ViewController.h"@interfaceViewController()@property(nonatomic,strong)UIImage*animatedImage;@end@implementationViewController-(void)viewDidLoad{[superviewDidLoad];self.animatedImage=[UIImage

ios - 视频轨道后面的 AVFoundation UIImage

我目前正在渲染一个小于输出大小但工作正常的视频轨道。我想将UIImage绘制到背景中,以便视频位于顶部,图像显示在视频不在的区域。我尝试将CoreAnimationLayers与videoCompositionCoreAnimationToolWithPostProcessingAsVideoLayer:inLayer一起使用:但是视频层下面的层似乎没有显示出来(上面的层显示得很好)-只是黑色或我在AVMutableVideoCompositionInstruction对象上设置的任何背景颜色。我也试过将该背景颜色设置为[UIColorclearColor].CGColor但它只是以黑

iphone - 来自 AVCaptureVideoPreviewLayer 的 UIImage

我正在尝试从视频源中抓取静止图像(基本上是暂停或“快照”功能)。我的项目是使用BenjaminLoulier'stemplate设置的.我的问题是,即使我通过prevLayer(AVCaptureVideoPreviewLayer)在屏幕上显示彩色视频,我已将视频设置设置为灰度,所以我无法从customLayer获取UIImage(一个普通的CALayer)。我尝试使用给定here的这个函数,但是由于某些愚蠢的原因(显示清晰/透明),这对AVCaptureVideoPreviewLayer不起作用。有谁知道将AVCaptureVideoPreviewLayer的内容保存为UIImage

iphone - 我如何将 UIImage 堆叠在一起并在 UIKit 中摇摆不定

我想知道这个应用程序如何在UIKit中堆叠uiimage和wavering。我正在关注这个xcode:UsingaUIImageViewsubclasswithNSTimers让图像随机下降,但我如何捕捉它并将UIImage堆叠在一起?感谢您的回复...编辑:为清楚起见https://www.youtube.com/watch?v=2dpZCoi4xFk40秒后将展示它如何堆叠在一起并随加速度计摆动这将模拟UIIimageView的下降-(void)viewDidLoad{[superviewDidLoad];//setthebackgroundcolortosomethingCOLD

ios - 如何使用 Accelerate Framework 将带有 mask 的图像组合成一个 UIImage?

此代码将图像和灰度蒙版图像组合成一个UIImage。它有效,但速度很慢。+(UIImage*)maskImage:(UIImage*)imagewithMask:(UIImage*)mask{CGImageRefimageReference=image.CGImage;CGImageRefmaskReference=mask.CGImage;CGImageRefimageMask=CGImageMaskCreate(CGImageGetWidth(maskReference),CGImageGetHeight(maskReference),CGImageGetBitsPerCompon

带边框的 iOS UIImage 有一个粗角半径

我正在尝试使用具有边框和圆角半径的CoreGraphics(通过PaintCode)在代码中构建UIImage。我发现图像的拐角处有明显较粗的边框。这似乎是一个iOS错误或我完全遗漏的东西。请指教。代码:CGRectrect=CGRectMake(0,0,53,100);////UIGraphicsforUIImagecontextCGContextRefcontext=UIGraphicsGetCurrentContext();UIGraphicsPushContext(context);UIGraphicsBeginImageContextWithOptions(rect.size

ios - 在单元测试中断言 UIImage 的最佳方式是什么?

假设我正在为ViewController上的tableView:cellForRowAtIndexPath:委托(delegate)方法编写单元测试。根据我传入的索引路径,此方法可以返回几个不同的单元格配置。我可以轻松断言cell.textLabel.text属性。但是我如何断言cell.imageView.image属性包含正确的图像?图像或imageView都没有(公共(public)API)属性,我可以使用它来查找图像名称或文件名。我想出的最好办法是创建smallestpossiblevalid.png(使用[UIImageimageWithData:]所以我在单元测试中不接触磁

ios - UIImage 在 iOS 中使用时看起来不同

我在处理png图像时遇到问题,与实际图像相比,它在iOS上的颜色有误。无论我如何使用图像,它总是得到错误的颜色。我试过UIButton和UIImageView,结果相同。这是UIImage的一种非常标准的用法:UIImage*greenButtonImg=[UIImageimageNamed:@"btn_green"];UIImageView*testView=[[UIImageViewalloc]initWithImage:greenButtonImg];[self.viewaddSubview:testView];第二张图片是它在iOS上的样子,第一个按钮是它在我的Mac(Find

iOS获取UIImage内存大小

我想获取UIImage对象的实际内存大小。有3种方法NSUIntegers1=UIImagePNGRepresentation(thumbImage).length;NSUIntegers2=UIImageJPEGRepresentation(thumbImage,1).length;NSUIntegers3=CGImageGetHeight(thumbImage.CGImage)*CGImageGetBytesPerRow(thumbImage.CGImage);NSLog(@"s1:%u",s1);NSLog(@"s2:%u",s2);NSLog(@"s3:%u",s3);和结果s