周精益分享 - 程序员装逼指南

『图像和滤镜』

图像

常见的图像格式

  • png(Portable Network Graphic)便携式网络图形格式
  • tiff、tif(Tagged Image File Format)标记图像文件格式
  • jpg、jpeg(Joint Photographic Experts Group)联合摄影专家组
  • gif(Graphic Interchange Format)图形交换格式

图像实例化

  • imageNamed:

    使用频率高,内存缓存优化

  • imageWithContentsOfFile:

    单次使用,暂时不清楚如何支持ImageAssert下的图片路径

  • imageWithData:

    本地或网络的文件数据加载

  • imageWithCGImage:

    绘制生成图,代码如下

1
2
3
4
5
// 旧图局部裁剪
CGImageRef myImageRef = [oldImage CGImageRef];
CGRect subRect = CGRectMake(20, 20, 100, 100);
CGImageRef cgCrop = CGImageCreateWithImageInRect(myImageRef, subRect);
UIImage *imageCrop = [UIImage imageWithCGImage:cgCrop];

显示图像

屏幕的缩放因子,导致我们需要@2x及@3x图,对视图截图操作也同样需要针对Retina及plus优化

1
2
3
4
5
6
7
8
9
10
11
- (UIImage*)screenShotBy:(UIImageView*)imagView
{
// UIGraphicsBeginImageContext(imagView.bounds.size);
// 2表示Retina,3表示plus分辨率,1正常,0则是当前设备的缩放因子
// YES 表示不包含图像的alpha通道
UIGraphicsBeginImageContextWithOptions((imagView.bounds.size), YES, 2);
[imagView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage*image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}

contentModel

图像内容展现方式

  • UIViewContentModelScaleToFill(默认)
  • UIViewContentModelScaleAspectFill(下拉放大)
  • UIViewContentModelScaleAspectFit
  • UIViewContentModelCenter (一些停靠模式)
  • UIViewContentModelTop/Bottom
  • UIViewContentModelLeft/Right
拉伸属性

代码

1
2
3
4
5
// 方法一
image=[oldIconImage stretchableImageWithLeftCapWidth:10 topCapHeight:12];
// 方法二
image = [oldIconImage resizableImageWithCapInsets:UIEdgeInsetsMake(17, 17, 17, 25)];

ImageAssert

Alt text
使用slicing,小变大无视差
Alt text


图像选择器

系统自带

自定义


滤镜

人脸识别