ios - Portrait image is not properly resizing -


landscape resizing portrait image not resizing properly. please me sort out problem. code :-

cgsize newsize = cgsizemake(width, height);  float widthratio = newsize.width/image.size.width*image.scale;  float heightratio = newsize.height/image.size.height*image.scale;  nslog(@" image size %f %f %f",image.size.width,image.size.height,image.scale);  if(widthratio > heightratio)      newsize=cgsizemake(image.size.width*heightratio,image.size.height*heightratio);   else      newsize=cgsizemake(image.size.width*widthratio,image.size.height*widthratio);  uigraphicsbeginimagecontextwithoptions(newsize, no, 0.0);  [image drawinrect:cgrectmake(0,0,newsize.width,newsize.height)];  uiimage* newimage = uigraphicsgetimagefromcurrentimagecontext();  uigraphicsendimagecontext(); 

try this:

- (uiimage*)resizeimage:(uiimage *)image imagesize:(cgsize)size {     cgfloat imagewidth = image.size.width;     cgfloat imageheight = image.size.height;     cgfloat requiredwidth = (imagewidth * size.height) / imageheight;      uigraphicsbeginimagecontextwithoptions(cgsizemake(requiredwidth, size.height), no, [uiscreen mainscreen].scale);     [image drawinrect:cgrectmake(0, 0, requiredwidth, size.height)];     uiimage* newimage = uigraphicsgetimagefromcurrentimagecontext();     //here scaled image has been changed size specified     uigraphicsendimagecontext();     return newimage; } 

Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -