【发布时间】:2016-06-23 05:25:36
【问题描述】:
我已经尝试了至少 5 种我在这里找到的不同方法,但都没有奏效。所有人都至少 1-2 岁。自那以后,Apple 是否改变了规则?
我截取屏幕截图,将其裁剪为正方形,然后尝试将其角裁剪为半径为 15。
也许有一种更严肃、更确定的方法可以用 OpenGL 做到这一点?
目前正在尝试这个解决方案,但角落仍然拒绝裁剪:
-(UIImage*) cropImage:(UIImage*)image withPath:(UIBezierPath*)path { // where the UIBezierPath is defined in the UIKit coordinate system (0,0) is top left
CGRect r = CGPathGetBoundingBox(path.CGPath); // the rect to draw our image in (minimum rect that the path occupies).
UIGraphicsBeginImageContextWithOptions(r.size, NO, 0.0); // begin image context, with transparency & the scale of the image.
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(ctx, -r.origin.x, -r.origin.y); // translate context so that when we add the path, it starts at (0,0).
CGContextAddPath(ctx, path.CGPath); // add path.
CGContextClip(ctx); // clip any future drawing to the path region.
[image drawInRect:(CGRect){CGPointZero, image.size}]; // draw image
UIImage* i = UIGraphicsGetImageFromCurrentImageContext(); // get image from context
UIGraphicsEndImageContext(); // clean up and finish context
return i; // return image
}
澄清一下,我实际上是在尝试删除我裁剪的像素
而我正在路过...
[self cropImage:myImage withPath:[UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, screenImage.size.width, screenImage.size.height) cornerRadius:15.0]]
即使我尝试大大增加拐角半径,仍然没有任何反应。
【问题讨论】:
-
发布你的尝试。
-
@code 刚刚发布
标签: ios objective-c uiimage crop rounded-corners