Skip to content

Latest commit

 

History

History
46 lines (31 loc) · 1.65 KB

技术成长.md

File metadata and controls

46 lines (31 loc) · 1.65 KB

技术成长

iOS截图大小多大

iOS有哪些截图方法

//1 绘制视图内容到当前context中
UIGraphicsBeginImageContext(self.frame.size);
[self drawViewHierarchyInRect:self.bounds afterScreenUpdates:YES];
UIImage *image1 = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
                
//2
UIView *snapshot = [self snapshotViewAfterScreenUpdates:YES];
                
//3 截图
UIGraphicsBeginImageContext(self.frame.size);
[self.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image2 = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

如何衡量图片大小

其实如果对图片有一定的基础的话就知道

  • 图片由多个像素组成的像素矩阵构成
  • 每个像素点由RGBA四个颜色通道组成(有些情况并非四个通道,比如没有alpha通道,比如灰度图可能只有一个通道)
  • 每个通道的颜色值可以用0-255之间的数来表示
  • 所以每个通道的颜色值都占用一定的字节数,对于iOS来说每个通道占1个字节

那基于上面的认知,一张未压缩的图片的实际大小,就是所有像素点占用的字节数了

  • 当然像png、jpeg这种格式的图片其实都是压缩过的数据了,所以大小会小一些

如何自定义一个视图

布局时机

如何实现动态布局