Tag: uiimage

如何将imageWithContentsOfFile用于animation中使用的图像数组?

这是我现在有: NSMutableArray *images = [[NSMutableArray alloc] initWithCapacity:21]; for(int count = 1; count <= 21; count++) { NSString *fileName = [NSString stringWithFormat:@"dance2_%03d.jpg", count]; UIImage *frame = [UIImage imageNamed:fileName]; [images addObject:frame]; } UIImage imageNamed导致我一些内存问题,我想切换到imageWithContentsOfFile。 我可以使它与单个图像,但不是整个数组: NSMutableArray *images = [[NSMutableArray alloc] initWithCapacity:21]; for(int count = 1; count <= 21; count++) { NSString *fileName = [[[NSBundle mainBundle] bundlePath] stringByAppendingString:@"/dance2_001.jpg"]; […]

iOS – 用button反转UIImage

我有一个简单的应用程序,我可以拍摄照片或select相机胶卷上的现有照片,然后在UIImageView中显示图像。 我想要一个button,您可以按下并反转选取的图像,然后在相机胶卷上显示。 我的问题是,如何反转UIImage的颜色,然后使用新的反转显示在ImageView? 我已经看到了与此相关的其他职位,但没有解释如何实现代码。 我对xcode相当陌生,并会感谢所有反馈。 这是我的视图控制器的.m文件: #import "ViewController.h" @interface ViewController () @end @implementation ViewController @synthesize imageView; – (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. } – (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } -(IBAction)takePhoto { picker1 = [[UIImagePickerController […]

在UIScrollView中像“移动和缩放”一样裁剪UIImage

如何在UIImagePickerController中创build自定义的“移动和缩放”视图? 我需要移动和缩放我的自定义UIImages,而不是从照片库。 或者也许有办法将UIImage传递给这个视图?

合并两个不同大小的图像旋转和缩放

我面临以下问题:我必须合并两个图像bottomImg和topImg,以创build一个新的图像C作为合并的结果。 我已经知道如何合并两个图像,但在这种情况下,我的目标有点不同。 顶部图像可能被缩放和旋转。 我已经按照这个答案 。 但是在这个解决scheme中,当我旋转时,顶部图像被剪切 模拟器 实际存储的图像是像文件一样 我已经尝试这个代码 bottomImg的_parentViewGIf和topImg的_ivGIF – (UIImage *)mergeImage:(UIImage *)bottomImg withImage:(UIImage *)topImg { float width=bottomImg.size.width*_ivGIF.frame.size.width/_parentViewGIf.frame.size.width; float height=bottomImg.size.width*_ivGIF.frame.size.height/_parentViewGIf.frame.size.width; UIImage * scaledTopImg = [self imageByScalingProportionallyWithImage:topImg ToSize:CGSizeMake(bottomImg.size.width, bottomImg.size.height)]; UIGraphicsBeginImageContext(scaledTopImg.size); CGContextRef ctx = UIGraphicsGetCurrentContext(); CGContextTranslateCTM(ctx, scaledTopImg.size.height * 0.5, scaledTopImg.size.height * 0.5); CGFloat angle = atan2(_ivGIF.transform.a, _ivGIF.transform.b); CGContextRotateCTM(ctx, angle); [scaledTopImg drawInRect:CGRectMake(- scaledTopImg.size.width * 0.5f, -(scaledTopImg.size.height * […]

从UIImage(照片库)获取RGB数据的快速方法

我想获得一个数据数组,其中包含存储在iOS(ios8 sdk)上的照片库(ALAsset)中的图片的RGB表示。 我已经试过这个方法: 使用[ALAssetRepresentation fullScreenImage]从ALAsset获取CGImage 将CGImage绘制到CGContext。 该方法的工作原理,我得到一个指向rgb数据,但这是非常缓慢 (有2个转换)。 最终目标是在OpenGL纹理中快速加载图像。 我的代码来从照片库中获取图像 ALAsset* currentPhotoAsset = (ALAsset*) [self.photoAssetList objectAtIndex:_currentPhotoAssetIndex]; ALAssetRepresentation *representation = [currentPhotoAsset defaultRepresentation]; //-> REALLY SLOW UIImage *currentPhoto = [UIImage imageWithCGImage:[representation fullScreenImage]]; 我的代码在CGContext上绘制: CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); NSUInteger bytesPerPixel = 4; NSUInteger bytesPerRow = bytesPerPixel * textureWidth; NSUInteger bitsPerComponent = 8; CGContextRef context = CGBitmapContextCreate(textureData, textureWidth, textureHeight, […]

方面填写导航栏图像?

我想要获得与我的导航控制器的背景图像相同的外观。 目前我正在使用它来设置图像: UINavigationBar.appearance().setBackgroundImage(imageToCache?.resizableImage(withCapInsets: UIEdgeInsetsMake(0, 0, 0, 0), resizingMode: UIImageResizingMode.stretch), for: .default) UIImageResizingMode.stretch显然给了我一个讨厌的拉伸外观。 我不在乎图像是在顶部/底部切断,我只是需要它被放入导航栏全尺寸,并显示显示。 我不能只是通过调整模式。 还有 init(rawValue:)) 选项的大小调整模式,但任何数字我放在那里导致没有图像在后台了。 有任何想法吗? 编辑: let picture = passedPerson.pictureURL! if let imageFromCache = MainPageVC.imageCache.object(forKey: picture as String as NSString) { var titleView = UIImageView() titleView.contentMode = .scaleAspectFit titleView.image = imageFromCache self.navigationItem.titleView = titleView } else { print(picture) var requested = URLRequest(url: […]

使用colorWithPatternImage在iOS中伸展图像

我有这样一个图像: 。 在iPad中,当我把它与这些代码: [separatorLineView setFrame:CGRectMake(10, 0, 430, 3)]; separatorLineView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"divider.png"]]; 在iPad中,它显示如下: 在iPhone中,它工作正常。 iPhone的代码如下所示: [separatorLineView setFrame:CGRectMake(10, 0, 180, 3)]; separatorLineView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"divider.png"]]; 如何避免重复? 我必须使用resizableImageWithCapInsets? 需要一些指导和build议..

无法将UIImage传递给MKPinAnnotationView

我subclassed MKPointAnnotation并添加一个NSString和一个UIImage所以我可以将这些元素传递给一个MKPinAnnotationView 。 该string传递到MKPinAnnotationView罚款,但图像属性是通过为空。 我无法弄清楚为什么。 我会说有一次在我的手机上运行这个代码的图像出现在一个针一次,所以也许我有一个内存泄漏? 其他1000次我编译的图像在日志中显示为空,并没有出现。 任何帮助表示赞赏。 这是我的子类customMapAnnotation.h: @interface customMapAnnotation : MKPointAnnotation @property (strong, nonatomic) NSString *restaurantID; @property (strong, nonatomic) UIImage *restaurantIcon; @end 这是我的customMapAnnotation创build的地方。 我正在使用Parse.com,所以这里有一个声明将PFFile转换为UIImage。 如果我检查日志,确认foodPoint.restaurantIcon在运行时有一个值。 customMapAnnotation *foodPoint = [[customMapAnnotation alloc] init]; foodPoint.coordinate = spot; foodPoint.restaurantID = [object objectId]; foodPoint.title = [object objectForKey:@"restaurantName"]; foodPoint.subtitle = [object objectForKey:@"cuisineType"]; leftIcon = [object objectForKey:@"restaurantImage"]; [leftIcon getDataInBackgroundWithBlock:^(NSData *data, […]

如何合并两个UIImages,同时保持其位置,大小和纵横比?

我正在尝试合并两个不同大小的UIImage 。 我有UIImage A是以下大小: 1287 × 1662像素和UIImage B具有以下大小: 200 × 200像素 我在下面的UIImageView显示A和B. UIImageView backgroundImageView的大小: 375 x 667和UIImageView foregroundImageView的大小: 100 x 100 用户可以将foregroundImageView移动到backgroundImageView上方的任何位置。 这是合并代码: let previewImage:UIImage? = mergeImages(img: imgBackground.image!, sizeWaterMark: CGRect.init(origin: imgForeground.frame.origin, size: CGSize.init(width: 100, height: 100)), waterMarkImage: imgForeground.image!) func mergeImages(img:UIImage, sizeWaterMark:CGRect, waterMarkImage:UIImage) -> UIImage { let size = self.imgBackground.frame.size UIGraphicsBeginImageContextWithOptions(size, false, UIScreen.main.scale) img.draw(in: getAspectFitFrame(sizeImgView: size, […]

如何从CIAreaHistogram中提取主色?

我正在寻找分析iOS上的UIImage(最像素的颜色)最主要的颜色,我偶然发现了核心图像的基于filter的API,特别是CIAreaHistogram。 似乎这个filter可能会帮助我,但我正在努力了解API。 首先它说filter的输出是一个一维图像,它是您的input框的长度和一个像素的高度。 我如何读取这些数据? 我基本上想要找出频率最高的颜色值,所以我期望数据包含每种颜色的某种频率计数,我不清楚这个一维图像是如何表示的,因为它不是真的解释我在这个一维图像内可以预期的数据。 如果它真的是一个直方图,为什么它不会返回一个像字典一样的数据结构 其次,在API中要求多个分档? 这个input应该是什么? 如果我想要一个精确的分析,inputbin参数是我的图像的色彩空间? 什么使仓值更小,我会想象它通过欧几里德距离近似的颜色接近最近的bin。 如果情况是这样,那么不会产生精确的直方图结果,为什么有人想要这样做? 从API的angular度对上述两个问题的任何意见都会对我有很大的帮助