Square thumbnail from UIImagePickerViewController image

后端 未结 4 1964
春和景丽
春和景丽 2020-12-24 08:34

In my app the user selects an image or take a picture using UIImagePickerViewController. Once the image was selected I want to display its thumbnail on a square UIImageView

4条回答
  •  死守一世寂寞
    2020-12-24 09:04

    Another way to do this - ran into an issue the other day and other people might have the same issue when using the apple sample code which is best for large images.

    As mentioned in the accepted answer, this has the problem of loading the entire image into memory and iOS can kill your app if it's too large. CGImageSourceCreateThumbnailAtIndex in Apple's example code is more efficient, however there is a bug in the example. The 3rd parameter in the CFDictionaryCreate is the "numValues" to copy. Needs to be 3 not 2.

    myOptions = CFDictionaryCreate(NULL, (const void **) myKeys,  
                                   (const void **) myValues, 
                                   3, //Changed to 3  
                                   &kCFTypeDictionaryKeyCallBacks,  
                                   & kCFTypeDictionaryValueCallBacks);  
    

提交回复
热议问题