2013-02-14 89 views
0

我想操纵视图上的UIImage对象。但是,当我尝试调用上的UIImage类的任何方法,它会抛出异常UIImage方法不被调用

2013-02-14 15:24:42.301 Test[4685:19a03] -[UIImage scaleToSize:]: unrecognized selector sent to instance 0x94642c0 
2013-02-14 15:24:42.303 Test[4685:19a03] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImage scaleToSize:]: unrecognized selector sent to instance 0x94642c0' 
*** First throw call stack:` 
(0x1cc1012 0x1ae6e7e 0x1d4c4bd 0x1cb0bbc 0x1cb094e 0x47ee9 0x47bc0 0xb0f817 0xb0f882 0xb0fb2a 0xb26ef5 0xb26fdb 0xb27286 0xb27381 0xb27eab 0xb27fc9 0xb28055 0xc2d3ab 0xa7e92d 0x1afa6b0 0x5c3fc0 0x5b833c 0x5b8150 0x5360bc 0x537227 0x5378e2 0x1c89afe 0x1c89a3d 0x1c66f61 0x1c66e1b 0x39117e3 0x3911668 0xa2e65c 0x31fcd 0x29d5) 
libc++abi.dylib: terminate called throwing an exception 

下面是我使用的代码:

UIImage *test = [[UIImage alloc] init]; 
    test = [UIImage imageNamed:@"image0.jpg"]; 
    [test scaleToSize:CGSizeMake(40.0f, 40.0f)]; 
+0

UIImage没有实现scaleToSize:方法。你正尝试使用一些第三方库可能? – Vladimir 2013-02-14 10:03:32

+0

删除scaleToSize,因为它不支持UIImage – 2013-02-14 10:07:24

+0

你没有在'scaleToSize'行上得到警告吗? – esh 2013-02-14 10:07:53

回答

-1

FIRST定义图像大小,然后它的规模。

UIImage *test = [[UIImage alloc] init; 
test = [UIImage imageNamed:@"image0.jpg"]; 
[test scaleToSize:CGSizeMake(40.0f, 40.0f)]; 

试试这条线code.Or使用这个图像中的UIImageView

+0

问题出在'scaleToSize'上。它不在UIImage中实现。 – esh 2013-02-14 10:06:56

+0

我在故事板项目中使用https://github.com/OmidH/Filtrr – 2013-02-14 10:12:24

+0

将此用于图像Image.transform = CGAffineTransformMakeScale(2,2); – user2064700 2013-02-14 10:14:41

0

看一看的UIImage's class reference。你不会找到你正在寻找的方法。也许你忘了添加你正在使用的类别(例如):

#import "UIImage+Scale.h" 
+0

我已经添加了#import“UIImage + Scale.h” – 2013-02-14 10:10:02

+0

我再次说'#import“UIImage + Scale.h”'只是为了给你一个可能的类别的例子,它允许你扩展'UIImage's。 .. – Peres 2013-02-14 10:11:07

+0

你也可以使用这个:https://github.com/mbcharbonneau/UIImage-Categories – Peres 2013-02-14 10:11:38