Android与iOS中实现图片的拉伸与平铺

来源:互联网 发布:linux 文件夹权限介绍 编辑:程序博客网 时间:2024/04/30 00:14

一. iOS:

1. 拉伸:实际严格来说,这里不能说是拉伸,因为iOS中是根据图片的某一像素进行复制扩展图片的大小,并非变更大小来改变图片大小。

iOS5之前使用:

UIImage的- (UIImage *)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth topCapHeight:(NSInteger)topCapHeight

iOS5之后使用:

- (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsetsNS_AVAILABLE_IOS(5_0);// create a resizable version of this image. the interior is tiled when drawn.

- (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets resizingMode:(UIImageResizingMode)resizingModeNS_AVAILABLE_IOS(6_0);// the interior is resized according to the resizingMode


2. 平铺:iOS中做平铺,比较奇怪,是使用UIColor的方法实现的

- (UIColor *)initWithPatternImage:(UIImage*)image;


二. Android:

1. 拉伸:Android中的拉伸和iOS中拉伸并不相同,这里的拉伸实际是真正的拉伸,即改变图片的大小,只是比较高级,可以指定拉伸区域和内容区域,具体的内部原理也可以看到,回头有机会会研究一下。之前已经进行了总结,真的非常强大的特性:

http://blog.csdn.net/colorapp/article/details/37829879


2. 平铺:这个比较有意思,很多同事都不知道这个,我也是查了一下,还是有两种方式可以实现,再次感叹Android SDK的强大和移动开发的相同特性。

http://blog.csdn.net/ajieyxw/article/details/6667106

http://blog.csdn.net/roserose0002/article/details/11130447


3.在Android Studio中做9patch图片的时候,遇到一个很坑的问题,图片总是边角有阴影,并且总是效果和iOS不一致。最后发现是.9把我图片的四边各一像素用来做黑边了,在ps中把四边往外扩大1像素,发现就好了。


0 0
原创粉丝点击