TableView get the network picture and set it to rounded corners (optimized, FPS)

Source: Internet
Author: User

The code address is as follows: <br>http://www.demodashi.com/demo/11088.html

First, the preparatory work
    • Examples are more streamlined, no special requirements, with Xocde8.0 version of the good
Second, the program implementation 1, the relevant code
    • In addition to the three-party library Sdwebimage Kingfisher, there are altogether two category and extension
    • OC Code

    • Swift Code

# # # #2, concrete implementation
Let's introduce the code implementation logic for the following OC
First we take advantage of the successful callback method added in the recent version of Sdwebimage

[self sd_setImageWithURL:url placeholderImage:[placeholder imageRoundCorner] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {  }];

This code we can see the callback success will have the image to return, when we pass the image processing, processing it into rounded, on the display on the ImageView,
The way to set the fillet is here with the Bezier curve (Uibezierpath)
Put some code on it.

// 开始绘图,创建上下文UIGraphicsBeginImageContextWithOptions(self.size, NO, self.scale);// 得到上下文  CGContextRef context = UIGraphicsGetCurrentContext();// 得到上下文大小  CGRect rect = CGRectMake(0, 0, self.size.width, self.size.height);// 等比例例  CGContextScaleCTM(context, 1, -1);// 移动画布位置  CGContextTranslateCTM(context, 0, -rect.size.height);
// 开始利用贝塞尔曲线话圆角图片    UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:CGRectInset(rect, borderWidth, borderWidth) byRoundingCorners:corners cornerRadii:CGSizeMake(radius, borderWidth)];    [path closePath];    CGContextSaveGState(context);    [path addClip];    CGContextDrawImage(context, rect, self.CGImage);    CGContextRestoreGState(context);

Finally get the picture

UIImage *image = UIGraphicsGetImageFromCurrentImageContext();UIGraphicsEndImageContext();
Third, the Operation effect

TableView get the network picture and set it to rounded corners (optimized, FPS)

The code address is as follows: <br>http://www.demodashi.com/demo/11088.html

Note: This copyright belongs to the author, by the demo master, refused to reprint, reprint need the author authorization

TableView get the network picture and set it to rounded corners (optimized, FPS)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.