如何从 自定义 相册中获取 所有图像 ? __
var fetchOptions = PHFetchOptions()
fetchOptions.sortDescriptors = [NSSortDescriptor(key:"creationDate", ascending: false)]
fetchOptions.predicate = NSPredicate(format: "mediaType = %d", PHAssetMediaType.Image.rawValue)
let allImages:PHFetchResult = PHAsset.fetchKeyAssetsInAssetCollection(albumList[index].collection, options: fetchOptions)
该代码块仅获取其中一些。谢谢。
-> albumList[index].collection
的类型是PHAssetCollection
对于Swift 4
使用这个答案为自己编辑了一点。
import Photos
func fetchCustomAlbumPhotos()
{
let albumName = "Album Name Here"
var assetCollection = PHAssetCollection()
var albumFound = Bool()
var photoAssets = PHFetchResult<AnyObject>()
let fetchOptions = PHFetchOptions()
fetchOptions.predicate = NSPredicate(format: "title = %@", albumName)
let collection:PHFetchResult = PHAssetCollection.fetchAssetCollections(with: .album, subtype: .any, options: fetchOptions)
if let firstObject = collection.firstObject{
//found the album
assetCollection = firstObject
albumFound = true
}
else { albumFound = false }
_ = collection.count
photoAssets = PHAsset.fetchAssets(in: assetCollection, options: nil) as! PHFetchResult<AnyObject>
let imageManager = PHCachingImageManager()
photoAssets.enumerateObjects{(object: AnyObject!,
count: Int,
stop: UnsafeMutablePointer<ObjCBool>) in
if object is PHAsset{
let asset = object as! PHAsset
print("Inside If object is PHAsset, This is number 1")
let imageSize = CGSize(width: asset.pixelWidth,
height: asset.pixelHeight)
/* For faster performance, and maybe degraded image */
let options = PHImageRequestOptions()
options.deliveryMode = .fastFormat
options.isSynchronous = true
imageManager.requestImage(for: asset,
targetSize: imageSize,
contentMode: .aspectFill,
options: options,
resultHandler: {
(image, info) -> Void in
self.photo = image!
/* The image is now available to us */
self.addImgToArray(uploadImage: self.photo!)
print("enum for image, This is number 2")
})
}
}
}
func addImgToArray(uploadImage:UIImage)
{
self.images.append(uploadImage)
}
对于Swift 2.1
import Photos
func FetchCustomAlbumPhotos()
{
var albumName = "SwiftAlbum"
var assetCollection = PHAssetCollection()
var albumFound = Bool()
var photoAssets = PHFetchResult()
let fetchOptions = PHFetchOptions()
fetchOptions.predicate = NSPredicate(format: "title = %@", albumName)
let collection:PHFetchResult = PHAssetCollection.fetchAssetCollectionsWithType(.Album, subtype: .Any, options: fetchOptions)
if let first_Obj:AnyObject = collection.firstObject{
//found the album
assetCollection = collection.firstObject as! PHAssetCollection
albumFound = true
}
else { albumFound = false }
var i = collection.count
photoAssets = PHAsset.fetchAssetsInAssetCollection(assetCollection, options: nil)
let imageManager = PHCachingImageManager()
// let imageManager = PHImageManager.defaultManager()
photoAssets.enumerateObjectsUsingBlock{(object: AnyObject!,
count: Int,
stop: UnsafeMutablePointer<ObjCBool>) in
if object is PHAsset{
let asset = object as! PHAsset
print("Inside If object is PHAsset, This is number 1")
let imageSize = CGSize(width: asset.pixelWidth,
height: asset.pixelHeight)
/* For faster performance, and maybe degraded image */
let options = PHImageRequestOptions()
options.deliveryMode = .FastFormat
options.synchronous = true
imageManager.requestImageForAsset(asset,
targetSize: imageSize,
contentMode: .AspectFill,
options: options,
resultHandler: {
(image, info) -> Void in
self.photo = image!
/* The image is now available to us */
self.addImgToArray(self.photo)
print("enum for image, This is number 2")
})
}
}
}
func addImgToArray(uploadImage:UIImage)
{
self.images.append(uploadImage)
}
我如何替换所有的url图像在Blogger。示例bp1.blogspot.com/image.jpg我想使用javascript或jquery将其更改为cdn.staticly.io/img/bp1.blogspot.com/image.jpg?format=webp 我不能一张一张地改变那些图片...有很多感谢
下面是我得到的控制台输出和错误: 下面是我按下Get Images按钮后的控制台输出,您可以看到图像的url为:
本文向大家介绍从PHP文件夹中获取所有图像,包括了从PHP文件夹中获取所有图像的使用技巧和注意事项,需要的朋友参考一下 glob函数可用于从特定文件夹获取图像。以下是相同的示例代码- 指定图像文件夹的路径,并提取所有扩展名为.png的文件。它们在foreach循环的帮助下显示- 基于包含所有图像的文件夹,返回存在于文件夹内的每个图像的路径。
问题内容: 我正在制作一个使用AVFoundation拍照的应用程序,我想将它们保存到自定义相册中,然后查询并显示在我的应用程序中。(除非用户希望,否则我不希望它们出现在一般的照片胶卷中)我真的找不到任何东西可以显示在Swift中如何做到这一点……或根本没有。我应该有其他方法吗? 我在SO上找到了这个示例,但是对我来说这没有意义,我无法使其正常工作。 任何帮助/说明都将非常棒! 问题答案: 这是我
我在UserProfile中添加自定义字段UserType作为字符串。我想更改我的获取值,并将该值传递到TempData中。 这是我在AccountController上的代码: 我对该方法进行了调试,以下是我掌握的信息: 有人对此有什么解决办法吗?我是ASP. NET的新手,但也许如果我实现自定义成员资格,它会工作,你觉得呢?你能给我一些例子吗?谢谢你们。 解决方案如下: `[HttpPost]
我创建了一个名为“albums”的自定义帖子类型。我有5个自定义字段在我的每个职位。3个文本字段、1个图像字段和1个文件上载字段。我在我的模板页面中得到了3个正确的文本值。但我无法获取图像和文件上传字段的url部分。这是我的密码: 这是我当前的输出 布谷鸟-1 鸟类 布谷鸟 662668245306_027; a56fe50_b.,图像/jpeg,http://localhost/YIB/word