ios - How to get requested image size for iOS8 PhotoKit? -



ios - How to get requested image size for iOS8 PhotoKit? -

i using code below fetching image:

[[phimagemanager defaultmanager] requestimageforasset:asset targetsize:cgsizemake(800, 600) contentmode:phimagecontentmodeaspectfill options:options resulthandler:^(uiimage *result, nsdictionary *info) { nslog(@"size:%@",nsstringfromcgsize(result.size)); }];

i'm requesting image size of 800 x 600, i'm getting image size of 45 x 60, poor-quality.

how can requested image size using photokit?

your (unnati's) self reply work, misses out on number of optimisations apple give in framework images display more quickly.

your original code pretty much correct, include options object don't need, , may have been causing problems if had set resizemode incorrectly on it. here code should work you, i've removed options object.

[[phimagemanager defaultmanager] requestimageforasset:(phasset *)asset targetsize:cgsizemake(800, 600) contentmode:phimagecontentmodeaspectfit options:nil resulthandler:^(uiimage *result, nsdictionary *info) { nslog(@"image size:%@",nsstringfromcgsize(result.size)); }];

this should simpler, , give optimisations apple provide framework free. here's explanation of get:

responding low quality image

the framework phone call result handler multiple times increasing quality images, allowing display user while wait final image. the documentation:

photos may phone call result handler block more once. photos first calls block provide low-quality image suitable displaying temporarily while prepares high-quality image. (if low-quality image info available, first phone call may occur before method returns.) when high-quality image ready, photos calls result handler 1 time again provide it.

this means resulthandler block needs safe phone call more 1 time - block in code logs size, , test image 2 log messages, first 1 low quality 40x26 px image, , 1 time again high quality image. if open ios photos app, can see low quality images briefly before appear sharpen - what's happening here.

using options.deliverymode = phimagerequestoptionsdeliverymodehighqualityformat prevents behaviour, , resulthandler called 1 time final image, suggest not setting alternative unless can't devise handler block (in real code) can called multiple times.

returning cached high quality image quickly

to provide final image quickly, framework provide image close requested size in final phone call resulthandler block, if has 1 cached already. if you're using uiimageview set contentmode of aspect fill or fit, won't problem, specify matching contentmode in image request. example, against test image, sec phone call resulthandler 1280x850 image, larger requested right ballpark. however, setting options.resizemode = phimagerequestoptionsresizemodeexact prevent behaviour , forcefulness framework resize fresh re-create of image rather using cached copy, takes time.

since photos framework doesn't crop images (even if inquire to, that's bug ;-)), won't exact size request, using phimagerequestoptionsresizemodeexact option. example, if request 800x600 image not in 4:3 ratio, photos can't homecoming image of size, gets close can - on latest image, request gets image of 800x531. means need able handle images aren't exact size request, might take advantage of optimisations in framework , avoid using phimagerequestoptionsresizemodeexact. the documentation again:

resizing match target size less efficient using fast resizing option.

(did have set phimagerequestoptionsresizemodefast in original options object, not included in question? may have been causing issue.)

image versions

it's possible request different versions of image, in self reply options.version = phimagerequestoptionsversioncurrent. 1 not required however, default current version.

ios iphone image ios8 photokit

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -