简体   繁体   English

iOS /目标C / UIImage:CGSize为什么导致崩溃?

[英]IOS/Objective C/UIImage: Why is CGSize causing crash?

I have the following line in a category designed to crop an image: 我在旨在裁剪图像的类别中有以下一行:

CGSize mainImageSize = self.size;

When I call the category, the app crashes at this point. 当我调用类别时,应用程序此时会崩溃。 The console shows: 控制台显示:

size    CGSize  (width=142, height=142) 
mainImageSize   CGSize  (width=2.121995791459338E-314, height=2.121995791459338E-314)

Similarly, if you hold the cursor over the self.size, it displays 142,142 while if you hold it over mainImageSize it shows 2.212..., 2.212... etc. 同样,如果将光标放在self.size上,则显示142,142,而如果将光标放在mainImageSize上,则显示2.212 ...,2.212 ...等。

While I can guess why self.size might equal 142x142--it is approximately the image size of the view (150x150) in the view controller, I would interpret this line to mean that we are setting a new variable mainImageSize to the construct CGSize, so I have no idea where the 2.12.. is coming from. 虽然我可以猜测self.size为何等于142x142,它大约等于视图控制器中视图的图像大小(150x150),但我会解释这一行以表示我们将新变量mainImageSize设置为结构CGSize,所以我不知道2.12 ..的来源。 As far as I know mainImageSize is not a reserved word although maybe it is. 据我所知mainImageSize不是保留字,尽管也许是。 I have certainly not defined it as a variable. 我当然没有将其定义为变量。

This category is called with the following line in the didFinishPickingMediaWithInfo method where chosen image is the image selected: 在didFinishPickingMediaWithInfo方法中的以下行中调用此类别,其中所选图像是所选图像:

UIImage *thumbnail = [chosenImage createThumbnailToFillSize:CGSizeMake(side, side)];

Can anyone walk me through what is actually happening here and hopefully suggest a way to do this that does not crash? 谁能指导我了解这里实际发生的事情,并希望提出一种不会崩溃的方法?

Thank you in advance for any suggestions. 预先感谢您的任何建议。

The: 该:

mainImageSize   CGSize  (width=2.121995791459338E-314, height=2.121995791459338E-314)

you obtain seems to be sort of FLOAT_MIN value, are you sure that the instance exists? 您获得的好像是FLOAT_MIN值,您确定实例存在吗? what about the method you use to create the thumb are you sure that is working fine? 您确定用来创建拇指的方法又如何呢?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM