Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

图片相关 #33

Open
ShannonChenCHN opened this issue Apr 27, 2017 · 4 comments
Open

图片相关 #33

ShannonChenCHN opened this issue Apr 27, 2017 · 4 comments

Comments

@ShannonChenCHN
Copy link
Owner

ShannonChenCHN commented Apr 27, 2017

  • 图片的本质
  • 图片的格式
    • PNG
    • JPEG
    • GIF
    • WebP
    • APNG
    • BPG
  • 图片编解码
  • 移动端的图片下载
  • 图片的显示、渲染
  • 图片处理
    • 美颜滤镜
    • 贴纸
    • 人脸识别
  • 生成图片
@ShannonChenCHN
Copy link
Owner Author

ShannonChenCHN commented Apr 28, 2017

@ShannonChenCHN ShannonChenCHN changed the title 【专题】图片相关 图片相关 Sep 19, 2017
@ShannonChenCHN
Copy link
Owner Author

@ShannonChenCHN
Copy link
Owner Author

ShannonChenCHN commented Mar 27, 2018

图片拉伸之点九图

什么是点九图

点九图(nine patch)是安卓开发中的概念。
.9.png确实是标准的PNG格式,只是在最外面一圈额外增加1px的边框,这个1px的边框就是用来定义图片中可扩展的和静态不变的区域。

iOS 中提供了 resizableImageWithCapInsets: 方法。

android 的做法的确更全面,比如说内容区域偏上几个像素,偏下几个像素,这些都是可以在图片上标识出来,再比如说一个图片单方向上有两个区域需要拉伸,这些都是ios不能简单实现的,而android的.9做到了。如图所示:

iOS 中的图片拉伸

UIImage 提供了以下几个方法用于图片拉伸。

第一种:

- (UIImage *)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth topCapHeight:(NSInteger)topCapHeight;  // iOS 2.0 ~ iOS 5.0
// 左端盖宽度  
NSInteger leftCapWidth = image.size.width * 0.5f;  
// 顶端盖高度  
NSInteger topCapHeight = image.size.height * 0.5f;  
// 重新赋值  
image = [image stretchableImageWithLeftCapWidth:leftCapWidth topCapHeight:topCapHeight];

注意:这个方法只能拉伸1x1的区域。

第二种:

- (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets; // iOS 5.0 及以后
CGFloat top = 25; // 顶端盖高度  
CGFloat bottom = 25 ; // 底端盖高度  
CGFloat left = 10; // 左端盖宽度  
CGFloat right = 10; // 右端盖宽度  
UIEdgeInsets insets = UIEdgeInsetsMake(top, left, bottom, right);  
// 伸缩后重新赋值  
image = [image resizableImageWithCapInsets:insets];  

第三种:这种方法可以指定拉伸模式是平铺还是拉伸。

- (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets resizingMode:(UIImageResizingMode)resizingMode; // iOS 6 及以后
CGFloat top = 25; // 顶端盖高度  
CGFloat bottom = 25 ; // 底端盖高度  
CGFloat left = 10; // 左端盖宽度  
CGFloat right = 10; // 右端盖宽度  
UIEdgeInsets insets = UIEdgeInsetsMake(top, left, bottom, right);  
// 指定为拉伸模式,伸缩后重新赋值  
image = [image resizableImageWithCapInsets:insets resizingMode:UIImageResizingModeStretch]; 

参考

@ShannonChenCHN
Copy link
Owner Author

ShannonChenCHN commented Jul 20, 2020

图片编解码

  • 图片是如何显示到屏幕上的
  • 为什么需要解码?
  • 常用的解码方案有哪些?

参考

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant