根据给定的 URL 创建缩略图(目前支持 PDF、图像和视频)。
ROThumbnailGenerator 可通过 CocoaPods 获得。要安装它,只需将以下行添加到您的 Podfile
pod "ROThumbnailGenerator"
ROThumbnail 类负责根据给定的 URL 创建缩略图。方法 getThumbnail(url:NSURL)
内部检查支持的文件类型,并使用 ROThumbnailGenerator 的相应实现。
目前支持以下文件类型
您可以根据以下方式检索给定 URL 的缩略图
var thumbnailImage = ROThumbnail.sharedInstance.getThumbnail(fileUrl)
如果您想添加 ROThumbnailGenerator 的新实现,可以通过实现 ROThumbnailGenerator 类,并定义您将使用此实现处理的文件扩展名。
以下是一个小的示例
class ImageThumbnailGenerator : ROThumbnailGenerator {
var supportedExtensions:Array<String> = ["png", "jpg", "jpeg"]
func getThumbnail(url:NSURL) -> UIImage {
return UIImage(data: NSData(contentsOfURL: url)!) ?? UIImage(named: "Piktogramm_IMAGE")!
}
}
您可以使用以下调用添加您的实现
ROThumbnail.sharedInstance.addThumbnailGenerator(yourThumbnailGenerator)
The MIT License (MIT)
Copyright (c) 2015 Robin Oster (http://prine.ch)
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Robin Oster,[email protected]