ios - Loss quality image in UIView -
ios - Loss quality image in UIView -
i've got problem images on app. in slide-out menu, i've got header set image "header.png" exist in 2 version "header.png" , "header@2x.png". here code how implement in app:
- (uiview *)tableview:(uitableview *)tableview viewforheaderinsection:(nsinteger)section { uiimage *originalimage = [uiimage imagenamed:@"header.png"]; cgsize destinationsize = cgsizemake(320, 150); uigraphicsbeginimagecontext(destinationsize); [originalimage drawinrect:cgrectmake(0,0,destinationsize.width,destinationsize.height)]; uiimage *newimage = uigraphicsgetimagefromcurrentimagecontext(); uigraphicsendimagecontext(); uiimageview *headerview = [[uiimageview alloc] initwithimage:newimage]; headerview.frame = cgrectmake(0,0, 320,150); homecoming headerview; }
when run app on phone (iphone 4s), image pixelate, border blowed , it's not clean... don't know comes from.
my images 320x150px , 640x300px in 72dpi
thx
--edit--
i've solved problem using uiimageview see below:
- (uiimageview *)tableview:(uitableview *)tableview viewforheaderinsection:(nsinteger)section { nsstring* filename = [nsstring stringwithformat:@"header.png"]; uiimage *newimage = [uiimage imagewithcontentsoffile:[[nsbundle mainbundle] pathforresource:filename oftype:nil]]; uiimageview *headerview = [[uiimageview alloc] initwithimage:newimage]; headerview.frame = cgrectmake(0, 0, [[uiscreen mainscreen] bounds].size.width, 150); homecoming headerview; }
the problem uigraphicsbeginimagecontext
doesn't provide retina image unless utilize uigraphicsbeginimagecontextwithoptions(destinationsize, no, scale)
where scale
could [uiscreen mainscreen].scale
.
just out of curiosity: why aren't using
uiimage *newimage = [uiimage imagenamed:@"header.png"] homecoming [[uiimageview alloc] initwithimage:newimage];
ios objective-c image uiview
Comments
Post a Comment