ios - Cropping ImageView in the Shape of Another ImageView -
how can crop imageview bubble shape have image in project.
following simple code resizing or crop image, need pass height or width image want:
for croped image:
uiimage *croppedimg = nil; cgrect croprect = cgrectmake(as need); croppedimg = [self croppingimagebyimagename:self.imageview.image torect:croprect];
use following method return uiimage
(as want size of image)
- (uiimage *)croppingimagebyimagename:(uiimage *)imagetocrop torect:(cgrect)rect { //cgrect croprect = cgrectmake(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height+15); cgimageref imageref = cgimagecreatewithimageinrect([imagetocrop cgimage], rect); uiimage *cropped = [uiimage imagewithcgimage:imageref]; cgimagerelease(imageref); return cropped; }
here croped image return above method;
or resizing
and use following method specific hight , width image resizing uiimage:
+ (uiimage*)resizeimage:(uiimage*)image withwidth:(int)width withheight:(int)height { cgsize newsize = cgsizemake(width, height); float widthratio = newsize.width/image.size.width; float heightratio = newsize.height/image.size.height; 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(); return newimage; }
this method return newimage, specific size want.
Comments
Post a Comment