Error when creating UIImage

70 views Asked by At

I am trying to create a thumbnail while importing a contact from the address book.

The method I'm using crashes at the line shown.

@implementation UIImage (Thumbnail)
-(UIImage *) createThumbnailToFillSize:(CGSize)size
{
    CGSize mainImageSize = self.size;//LINE WHERE IT CRASHES

    UIImage *thumb;

The last lines in the console are:

self    UIImage *const  0x7fb2ee0994e0  0x00007fb2ee0994e0
size    CGSize  (width=142, height=142) 
mainImageSize   CGSize  (width=10, height=0)

I'm thinking the error might have something to do with height=0 but I don't know how to change this or what self.size really refers to.

The code I'm working with came from a book on learning IOS.

Has anyone seen this or can suggest how to fix?

Edit:

Code calling category

// ...get permission to open contact, begin to extract contact info
     if (ABPersonHasImageData(addressBookRecord)) {
                CFDataRef imageData = ABPersonCopyImageData(addressBookRecord);

                UIImage *fullSizeImage = [UIImage imageWithData:(__bridge NSData *)imageData];

                CGFloat side = 71.f;
                side *= [[UIScreen mainScreen] scale];

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

                self.imageData = UIImageJPEGRepresentation(thumbnail, 1.f);

                CFRelease(imageData);
            }
1

There are 1 answers

0
Himanshu gupta On BEST ANSWER

Try size instead of self.size in the below line:

CGSize mainImageSize = self.size;//LINE WHERE IT CRASHES