cocoa touch - Should we scale image before setting it to a imageView in UITableView -
i displaying list of images names, chevron accessory see full size version of selected image.
i see scrolling performance not super smooth. think reason image assigning imageview of each cell full size image (which gets scaled down automatically before display).
will performance improve if maintain smaller image of "thumbnail" size? if yes, best way this? see example in how resize images in uitableviewcell?. answer (reproduced below) uses approach below, enough?
also, other tips make scrolling smoother?
cgsize itemsize = cgsizemake(30, 30); uigraphicsbeginimagecontext(itemsize); cgrect imagerect = cgrectmake(30.0, 30.0, itemsize.width, itemsize.height); [thumbnail drawinrect:imagerect]; cell.imageview.image = uigraphicsgetimagefromcurrentimagecontext(); uigraphicsendimagecontext();
yes, scaling down image helps lot. created method below resize following (and call on background thread keep main ui thread humming)
i also, found calling reloaddata on row changed helps using
[self.tableview reloadrowsatindexpaths:[nsarray arraywithobject:indexpath] withrowanimation:uitableviewrowanimationnone]; method used downsize.
- (uiimage *) returnthumbnail:(uiimage*)image { cgsize itemsize = cgsizemake(120, 90); uigraphicsbeginimagecontext(itemsize); cgrect imagerect = cgrectmake(0.0, 0.0, itemsize.width, itemsize.height); [image drawinrect:imagerect]; uiimage *scaledimage = uigraphicsgetimagefromcurrentimagecontext(); uigraphicsendimagecontext(); nslog(@"returning scaled image %@",scaledimage) ; return scaledimage ; }
Comments
Post a Comment