[IOS] Uiimageview Increase fillet angle

Source: Internet
Author: User

[IOS] Uiimageview Increase fillet angle

"How do I add rounded corners to a uiimageview?" There are several ways? Their differences? "

Note: This document is referenced from http://www.jianshu.com/p/d1954c9a4426

UIImageView *poImgView = [[UIImageView alloc]init];
Scenario A (basic scenario):
poImgView.layer.cornerRadius = poImgView.frame.size.width/2.0;poImgView.layer.masksToBounds = YES;(或者 poImgView.clipsToBounds = YES;)

Note: Clipstobounds is a cut on view, maskstobounds is a layer cut

Performance consumption:
This is off-screen rendering (off-screen-rendering), which consumes a large performance
FPS is approximately 45 frames (2 ImageView per cell)

Normal FPS is 60 frames, the smaller the user experience the worse

|

Off-screen rendering, which refers to the GPU opening a new buffer outside the current screen buffer for rendering operations. By one of the above conclusions the size of the view and fillet is not affected by the rate of the frame, the quantity is the core output of the damage. It is possible to know that the off-screen rendering time is taking place on the off-screen action, rather than rendering. Why is it so time-consuming to get off screen? The main reasons for this are creating buffers and context switches. The cost of creating a new buffer is not large, and the most costly is context switching.

Programme B:
CAShapeLayer *layer = [CAShapeLayer layer];  UIBezierPath *aPath = [UIBezierPath bezierPathWithOvalInRect:aImageView.bounds]; layer.path = aPath.CGPath; poImgView.layer.mask = layer;

Performance consumption:
The test FPS is approximately 20 frames, which is much more expensive than program a

Programme c:
- (UIImage *) Imagewithcornerradius: (CGFloat) Radius {CGRect rect = (CGRect) {0.F,0.F,Self. size};uigraphicsbeginimagecontextwithoptions (self.size, no, uiscreen .mainscreen.scale); cgcontextaddpath (uigraphicsgetcurrentcontext (), [uibezierpath bezierpathwithroundedrect:rect Cornerradius:radius] cgcontextclip (uigraphicsgetcurrentcontext ()); [ self Drawinrect:rect]; uiimage *image =  Uigraphicsgetimagefromcurrentimagecontext (); uigraphicsendimagecontext (); return image;}             

Performance consumption:
This is on-screen-rendering.
Equivalent to rendering at all times, compared to the offline rendering of the A.B scheme, this method has the lowest performance consumption and is recommended for this scenario.

Description

Both scenario A and scenario B are common, but none are recommended, and the optimization scenario for this is C, but if the cost of a or B scenario is used, the remedy is:

1. Rasterize: Generate a separate image of all cell contents, display only the image when the screen scrolls; This implicitly creates a bitmap, and the effects of various shadow masks are also saved in the map and cached, thus reducing the frequency of rendering (not vectors); This command causes the view render content to be cached. The cache is displayed directly the next time it is drawn.

  self.layer.shouldRasterize = YES;

2. Specify the resolution, otherwise the default use of the image, you need to specify the screen to match the resolution

  self.layer.rasterizationScale = [UIScreen mainScreen].scale;

[IOS] Uiimageview Increase fillet angle

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.