ios - SDWebImage resizing with UIGraphicsBeginImageContextWithOptions -


i'm using sdwebimage download thumbnails. resize them before caching them using - (uiimage *)imagemanager:(sdwebimagemanager *)imagemanager transformdownloadedimage:(uiimage *)image withurl:(nsurl *)imageurl delegate method.

the code use reisze images is:

- (uiimage *)imagebyscalingandcroppingforsize:(cgsize)targetsize image:(uiimage *)image {     uiimage *sourceimage = image;     uiimage *newimage = nil;     cgsize imagesize = sourceimage.size;     cgfloat width = imagesize.width;     cgfloat height = imagesize.height;     cgfloat targetwidth = targetsize.width;     cgfloat targetheight = targetsize.height;     cgfloat scalefactor = 0.0;     cgfloat scaledwidth = targetwidth;     cgfloat scaledheight = targetheight;     cgpoint thumbnailpoint = cgpointmake(0.0, 0.0);      if (cgsizeequaltosize(imagesize, targetsize) == no) {         cgfloat widthfactor = targetwidth / width;         cgfloat heightfactor = targetheight / height;          if (widthfactor > heightfactor) {             scalefactor = widthfactor; // scale fit height         } else {             scalefactor = heightfactor; // scale fit width         }          scaledwidth = width * scalefactor;         scaledheight = height * scalefactor;          // center image         if (widthfactor > heightfactor) {             thumbnailpoint.y = (targetheight - scaledheight) * 0.5;         } else {             if (widthfactor < heightfactor) {                 thumbnailpoint.x = (targetwidth - scaledwidth) * 0.5;             }         }     }      uigraphicsbeginimagecontextwithoptions(targetsize, yes, 0); // crop      cgrect thumbnailrect = cgrectzero;     thumbnailrect.origin = thumbnailpoint;     thumbnailrect.size.width = scaledwidth;     thumbnailrect.size.height = scaledheight;      [sourceimage drawinrect:thumbnailrect];      newimage = uigraphicsgetimagefromcurrentimagecontext();     uigraphicsendimagecontext();     return newimage; } 

at first, used uigraphicsbeginimagecontext(targetsize); images blurry on retina deivces changed function uigraphicsbeginimagecontextwithoptions(targetsize, yes, 0);

but images appear bigger in tableview cells. seems resizing code makes higher definition images sdwebimage library doesn't know how load them correctly.

correctly sized images @ bottom, top ones don't have correct size.

thanks in advance help

figured out,

you can specify uiimageview it's loading retina image setting image uiimage imagewithcgimage:image.cgimage scale:[[uiscreen mainscreen] scale] orientation:image.imageorientation];


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -