Sunday, 15 January 2012

ios - UIImage size returned from 'requestImageForAsset' is not even close to the 'targetSize' setting -



ios - UIImage size returned from 'requestImageForAsset' is not even close to the 'targetSize' setting -

i've thoroughly read through latest ios8 photo frame work , trying fetch assets users library display. allow user edit 4 images @ once. because of this, need compress images otherwise app crash.

i using phimagemanager load images via next code:

func processimages() { println("processing") _selectediimages = array() _cacheimagecomplete = 0 asset in _selectedassets { var options:phimagerequestoptions = phimagerequestoptions() options.version = phimagerequestoptionsversion.unadjusted options.synchronous = true var minratio:cgfloat = 1 if(cgfloat(asset.pixelwidth) > uiscreen.mainscreen().bounds.width || cgfloat(asset.pixelheight) > uiscreen.mainscreen().bounds.height) { minratio = min(uiscreen.mainscreen().bounds.width/(cgfloat(asset.pixelwidth)), (uiscreen.mainscreen().bounds.height/cgfloat(asset.pixelheight))) } var size:cgsize = cgsizemake((cgfloat(asset.pixelwidth)*minratio),(cgfloat(asset.pixelheight)*minratio)) println("target size \(size)") phimagemanager.defaultmanager().requestimageforasset(asset, targetsize:size, contentmode: .aspectfill, options: options) { uiimageresult, info in var image = iimage(uiimage: uiimageresult) println("result size \(uiimageresult.size)") } } }

as can see, calculating target size create sure image @ to the lowest degree no bigger screen. if is, ratio scale downwards on image. here typical print log

target size (768.0,798.453531598513) result size (1614.0,1678.0)

even though setting target size 768x798 (in specific case) resulting uiimage it's giving me more double that. according documentation, targetsize parameter

"the target size of image returned."

not clearest explanation experiments not matching this.

if have suggestions i'd love hear it!

try set resizemode phimagerequestoptionsresizemodeexact , deliverymode phimagerequestoptionsdeliverymodehighqualityformat;

phimagerequestoptionsresizemodeexact, // same above guarantees delivered image targetsize (must set when normalizedcroprect specified)

ios memory-management swift uiimage phasset

No comments:

Post a Comment