开发者

how to crop image in to pieces using - (UIImage *)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth topCapHeight:(NSInteger)topCapHeight

i need to crop single image into 9 pieces.

for that most of them suggest the fallowing method.

 - (UIImage *)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth topCapHeight:(NSInteger)topCapHeight

But i did n't fine any where how do it using this.

can any one please help me.开发者_Python百科

how can i crop image using this method.

Thank u in advance.


The method stretchableImageWithLeftCapWidth:topCapHeight is not cropping the image. It allows you to stretch an image with vertical and horyzontal margin.

In the doc you will read :

stretchableImageWithLeftCapWidth:topCapHeight: Creates and returns a new image object with the specified cap values.

To crop an image you should use CGImageCreateWithImageInRect :

CGImageCreateWithImageInRect Creates a bitmap image using the data contained within a subregion of an existing bitmap image.

You can achieve what you want with a method such as this one :

- (UIImage *)imageFromImage:(UIImage *)image inRect:(CGRect)rect {

    CGImageRef sourceImageRef = [image CGImage];  
    CGImageRef newImageRef = CGImageCreateWithImageInRect(sourceImageRef, rect);  
    UIImage *newImage = [UIImage imageWithCGImage:newImageRef scale:1.0 orientation:image.imageOrientation];
    CGImageRelease(newImageRef);
    return newImage;
} 

Hope this helps, Vincent

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜