-(void)cutOutImage:(UIImage *)cutedImage{
//设置要保存图片的大小
CGSize subImageSize=cutLocation.textureRect.size;
//初始化一个矩形
CGRect subImageRect=CGRectMake(KcutStartX, KcutStartY, KcutWidth, KcutHeight);
CGImageRef imageRef=cutedImage.CGImage;
CGImageRef subImageRef=CGImageCreateWithImageInRect(imageRef, subImageRect);
UIGraphicsBeginImageContext(subImageSize);
CGContextRef context=UIGraphicsGetCurrentContext();
CGContextDrawImage(context, subImageRect, subImageRef);
UIImage *subImage=[UIImage imageWithCGImage:subImageRef];
UIGraphicsEndImageContext();
[centerBg removeChild:selectedImage cleanup:YES];
[selectedImage release];
selectedImage=[[CCSprite alloc] initWithCGImage:subImage.CGImage];
selectedImage.position=ccp(160,240);
[centerBg addChild:selectedImage];
}
本文介绍了一种使用Objective-C实现的从原始UIImage中裁剪特定区域的方法,并将裁剪后的图片显示在视图中。该过程涉及创建一个指定大小的矩形,通过CGImageCreateWithImageInRect获取裁剪后的图片,再利用UIGraphicsBeginImageContext和UIGraphicsGetCurrentContext将其绘制到新的上下文中。
1630

被折叠的 条评论
为什么被折叠?



