iOS Photo Manipulator
一个用于 iOS 上程序性编辑图像的图像处理库。该库被 react-native-photo-manipulator 使用。
安装
在 Podfile 中添加依赖
# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
target 'Demo' do
# Uncomment the next line if you're using Swift or would like to use dynamic frameworks
# use_frameworks!
# Add WCPhotoManipulator
pod 'WCPhotoManipulator', :git => 'https://github.com/guhungry/ios-photo-manipulator.git', :tag => 'v1.0.0'
end
使用方法
使用以下命令导入
@import WCPhotoManipulator;
使用 UIImage+PhotoManipulator
[image crop]
从指定的 cropRegion
裁剪图像
名称 | 类型 | 必需 | 描述 |
---|---|---|---|
cropRegion | CGRect | 是 | 裁剪区域在CGRect(x , y , size , width )中 |
缩放 | CGFloat | 否 | 结果图像的缩放比例。默认 = 图像.scale |
[图像缩放]
使用cover
模式,将图像从指定大小调整为targetSize
名称 | 类型 | 必需 | 描述 |
---|---|---|---|
targetSize | CGSize | 是 | 结果图像的大小 |
缩放 | CGFloat | 否 | 结果图像的缩放比例。默认 = 图像.scale |
[图像绘制文本]
将文本打印到图像中
名称 | 类型 | 必需 | 描述 |
---|---|---|---|
text | NSString | 是 | 要打印到图像中的文本 |
position | CGPoint | 是 | 在x , y 坐标中的位置 |
color | UIColor* | 是 | 文本颜色 |
textSize | CGFloat | 是 | Text size |
厚度 | Float | 否 | 文本轮廓。默认 = 0 |
缩放 | CGFloat | 否 | 结果图像的缩放比例。默认 = 图像.scale |
[图像覆盖图像]
在背景图像上方覆盖图像
名称 | 类型 | 必需 | 描述 |
---|---|---|---|
overlay | UIImage* | 是 | 覆盖图像 |
position | CGPoint | 是 | 覆盖图像在背景图像中的位置 |
使用FileUtils
[FileUtils createTempFile]
在缓存目录中创建具有前缀的临时文件
名称 | 类型 | 必需 | 描述 |
---|---|---|---|
prefix | NSString | 是 | 临时文件名前缀 |
mimeType | NSString | 是 | 图片的Mime类型。默认 = image/jpeg |
[FileUtils cachePath]
获取应用程序的缓存路径
[FileUtils cleanDirectory]
删除目录中以指定前缀开头的所有文件
名称 | 类型 | 必需 | 描述 |
---|---|---|---|
目录 | NSString | 是 | 要清理的路径 |
prefix | NSString | 是 | 要匹配的文件名前缀 |
[FileUtils saveImageFile]
将图像保存到目标路径
名称 | 类型 | 必需 | 描述 |
---|---|---|---|
图像 | UII 图像 | 是 | 源图像 |
mimeType | NSString | 是 | 目标文件的Mime类型 |
质量 | CGFloat | 是 | 图像质量介于 0 - 1(仅适用于 jpg) |
文件 | NSString | 是 | 目标文件路径 |
[FileUtils imageFromUrl]
将文件从URI作为输入流打开
名称 | 类型 | 必需 | 描述 |
---|---|---|---|
uri | 字符串 | 是 | 图像的URI可以是远程的(https?://)或本地的(file://) |
使用 MimeUtils
[MimeUtils toExtension]
从 mimeType 获取图像文件扩展名(支持 .jpg, .png 和 .webp)
名称 | 类型 | 必需 | 描述 |
---|---|---|---|
mimeType | 字符串 | 是 | 图像mime类型 |