Tag: uiimage

Objective-C:将图像与以前保存的其他图像进行比较

我有一个关于在Objective-C中比较UIImage的问题,当一个图像已经通过使用NSSearchPathForDirectoriesInDomains方法的保存和加载过程。 我想要的目标是指导用户到一个新的屏幕上点击取决于图像显示。 为了简单起见,假设有两种可能性 – 黑色图像和绿色图像。 点击黑色的图像将您带到xib1,然后点击绿色的图像将您带到xib2。 这很简单,直到我实现了一个保存和加载系统。 为了节省我做了以下几点: paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); documentsDirectory = [paths objectAtIndex:0]; pngFilePath = [NSString stringWithFormat:@"%@/test.png",documentsDirectory]; data1 = [NSData dataWithData:UIImagePNGRepresentation([level1part1 objectAtIndex:0])]; [data1 writeToFile:pngFilePath atomically:YES]; 并加载我做了以下几点: paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); documentsDirectory = [paths objectAtIndex:0]; pngFilePath = [NSString stringWithFormat:@"%@/test.png",documentsDirectory]; UIImage *image = [UIImage imageWithContentsOfFile:pngFilePath]; [button1 setImage:image forState:UIControlStateNormal]; 这很好,当我退出程序并重新启动时,图像保留在屏幕上,因为我希望它。 假设我们假设现在出现在button1上的图像是绿色的图像。 当我点击发件人ID(这是button1)的button后,我调用下面的代码: if(sender.currentImage […]

在UIImageView中加载animation的图像 – iOS

我有大约300个图像加载animation图像被命名为loading001.png, loading002.png, loading003.png, loading004.png………loading300.png 我正在这样做。 .h文件 #import <UIKit/UIKit.h> @interface CenterViewController : UIViewController { UIImageView *imgView; } @end .m文件 @implementation CenterViewController – (void)viewDidLoad { [super viewDidLoad]; imgView = [[UIImageView alloc] init]; imgView.animationImages = [[NSArray alloc] initWithObjects: [UIImage imageNamed:@"loading001.png"], [UIImage imageNamed:@"loading002.png"], [UIImage imageNamed:@"loading003.png"], [UIImage imageNamed:@"loading004.png"], nil]; } – (IBAction)startAnimation:(id)sender{ [imgView startAnimating]; } @end 有没有一种有效的方法来将图像加载到数组中。 我曾尝试过for loop但无法弄清楚。

如何使用

我想拉伸尺寸为170×50的图像,并在尺寸为240×140的图像视图中显示。 原始图像看起来像: 我想保持四个angular落,只有拉伸中心部分。 我使用下面的代码: UIImage *originalImg = [UIImage imageNamed:@"ImageNamed"]; UIImage *resizeImg = [originalImg resizableImageWithCapInsets:UIEdgeInsetsMake(20 ,10, 10, 10)]; self.originalImgV.image = originalImg; self.resizedImgV.image = resizeImg; originalImgV和resizedImgV都设置为“纵横填充”。 我在模拟器上运行它,结果是: 我无法理解的是:resizedImgV有2个箭头! 任何人都可以告诉我为什么,如何正确使用它? 谢谢

UIImageJPEGRepresentation返回nil

我使用CIFilters将图像转换为灰度并应用一些image processing效果。 在UIImageView中显示输出结果 图像显示并已按预期进行了修改。 但是,调用UIImageJPEGRepresentation似乎每次都不返回任何数据。 它从来没有工作。 调用UIImageJPEGRepresentation使用原始的彩色图像工作正常。 这里发生了什么? 为什么在显示图像时jpeg转换失败可以正常工作? 不会引发任何exception(设置exception断点,没有命中),控制台中不会显示任何消息。 let _cicontext = CIContext(options:nil) // Set up grayscale and blur filters: let grayIze = CIFilter(name: "CIColorControls") let blur = CIFilter(name: "CIGaussianBlur") grayIze.setValue(0, forKey:kCIInputSaturationKey) grayIze.setValue(0.5, forKey: kCIInputBrightnessKey) blur.setValue(4, forKey: kCIInputRadiusKey) // Go! let originalImage = CIImage(image: colorImageThatDefinitelyExists) grayIze.setValue(originalImage, forKey: kCIInputImageKey) blur.setValue(grayIze.outputImage, forKey: kCIInputImageKey) let output = […]

如何将所有图像格式转换成.png格式?

我正在制作一个小型应用程序,用于从networking服务接收图像。 我正在获取图片url。 和图像的格式是不同的,如.jpg,.gif,.png等。我想将这些图像保存到我的沙箱,然后显示在图像视图。 为了做到这一点,我给了一个自己的名字,并给了扩展名为.png。 但在检索时,显示的图像,但不同的人没有显示。 那么你能给我任何想法如何将所有图像转换为.png格式或任何其他方法来做到这一点?

用CIFilter无法从CIImage中提取UIImage

我有这个新的iOS 8 Swift项目,并在其视图控制器之一,我必须设置图像。 但是,在将图像发送到视图之前,我想要使用CIFilter更改图像的对比度: 所以这是我的代码: view = UIImageView(frame:CGRectMake(0, 0, 200, 200)) var lecturePicture = UIImage(named: "placeholder") var beginImage = lecturePicture?.CIImage var controlsFilter = CIFilter(name: "CIColorControls") controlsFilter.setValue(beginImage, forKey: kCIInputImageKey) controlsFilter.setValue(1.5, forKey: "inputContrast") var displayImage = UIImage(CIImage: controlsFilter.outputImage) // breakpoint (view as UIImageView!).image = displayImage 那么,我只是简单地得到一个图像,应用一个转换,然后获得转换后的版本作为UIImage并将其设置回我的视图。 但是我只有一个错误: fatal error: unexpectedly found nil while unwrapping an Optional value […]

UIImageView自动resize

我想设置一个图像到UITableView的SimpleTableCell的UIImageView 。 我已经改变了imageview的大小,但每当我尝试设置图像,它会自动调整自己。 我试图使用这里的代码来调整图像的大小,并设置它。 但它只适用于将图像尺寸设置为(20×20),这是UIImageView (40×40)大小的一半。 所以变得模糊了。 我也尝试设置UIAspectRatioFit/UIAspectratioFill和clipsToBounds = YES 。 似乎没有任何工作。 另一个奇怪的部分是,当我使用从web直接下载的图像时, imageView不会自动resize,如下所示: – (void)connectionDidFinishLoading:(NSURLConnection *)connection { UIImage *userImage = [UIImage imageWithData:userImageData scale:self.profileImage.frame.size.height/self.profileImage.frame.size.width]; UITableViewCell *cell = [self.myTable cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]]; cell.imageView.image = userImage; } 但是,然后我把这个图像存储到文档目录,然后尝试重新加载在其他地方,resize发生。 任何解决scheme

从CGImageRef的UIImage

我正在尝试一个更复杂的项目的简单testing,但我为什么下面的代码崩溃并给出EXC_BAD_ACCESS错误感到困惑? 这是从UIView调用的。 – (void)testing { NSString *imagePath = [[NSBundle mainBundle] pathForResource:@"ball.png" ofType:nil]; CGImageRef imageRef = [[[UIImage alloc]initWithContentsOfFile:imagePath]CGImage]; // CGImageRetain(imageRef); UIImage *newImage = [[UIImage alloc]initWithCGImage:imageRef]; UIImageView *iv = [[UIImageView alloc]initWithImage:newImage]; [self addSubview:iv]; } 我的猜测是CGImageRef不被保留,但添加CGImageRetain(imageRef); 没有区别。 我也应该注意到这个项目已经开启了ARC。 编辑 我做了一些更多的testing,发现这与ARC直接相关,因为我创build了两个基本项目,只包括上面的代码。 ARC的第一个closures,它完美的工作。 下一个与ARC打开和BAM崩溃与相同的错误。 有趣的是,我第一次在崩溃之前运行项目时,得到了实际的日志错误。 Error: ImageIO: ImageProviderCopyImageBlockSetCallback 'ImageProviderCopyImageBlockSetCallback' header is not a CFDictionary…

NSData contentsOfUrl返回nil

我在StackOverflow上发现了几个类似的问题,但是没有一个解决我的问题。 我正在尝试从url获取图片。 以下是我如何做到这一点: let url = NSURL(string: "http://pic3.zhimg.com/8161ba9638273e0fb1a0201789d22d8e_m.jpg") let data = NSData(contentsOfURL: url!) let image = UIImage(data: data!) 但是我得到一个错误,告诉我data是零。 我该如何解决这个问题? 谢谢。 UPDATE 以下是错误的一些截图:

layer.renderInContext不考虑layer.mask?

我正在尝试将一些UIImage渲染成我可以保存在我的相册中的单个图像。 但是,似乎layer.renderInContext没有考虑到图层遮罩? 目前的行为:照片保存,我看到mosaicLayer,没有掩码效果的maskLayer。 预期的行为:照片保存,我看到我的视图中的图像,顶部是一个蒙面的mosaicLayer。 我使用下面的代码来掩盖图像 UIImage *maskImg = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"mask" ofType:@"png"]]; maskLayer = [[UIImageView alloc] initWithImage:maskImg]; maskLayer.multipleTouchEnabled = YES; maskLayer.userInteractionEnabled = YES; UIImageView *mosaicLayer = [[UIImageView alloc] initWithImage:img]; mosaicLayer.contentMode = UIViewContentModeScaleAspectFill; mosaicLayer.frame = [imageView bounds]; mosaicLayer.layer.mask = maskLayer.layer; [imageView addSubview:mosaicLayer]; 然后我使用这段代码保存我的合成图像: UIGraphicsBeginImageContext(imageView.bounds.size); [imageView.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *saver = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); UIImageWriteToSavedPhotosAlbum(saver, self, @selector(image:didFinishSavingWithError:contextInfo:), nil); […]