繁体   English   中英

Swift-在Spotlight搜索中获取圆形图像(即在缩略图中)

[英]Swift - Get a Circular Image in Spotlight Search (i.e. in the thumbnail)

是否有人对如何裁剪出现在聚光灯搜索中的图像有任何想法,以便“ thumbnailData”是圆形图像而不是方形图像?

这取自RayWenderlich.com

这些解决方案均无法达到预期效果: 将UIImage切成圆圈Swift(iOS)

我可以成功裁剪图像,但是聚光灯功能会在裁剪/遮罩的边框周围放置白色背景。 聚光灯联系人(kUTTypeContact)可能存在,但我所看到的内容(kUTTypeContent)却没有。

这是我的代码,供您偷看其他棺材:

    // For storing attributes into Searchable Dictionary
    internal var attributeSet: CSSearchableItemAttributeSet {
    let attributeSet = CSSearchableItemAttributeSet(itemContentType: kUTTypeContent as String)
    attributeSet.title = "\(firstName) \(surname)"
    attributeSet.contentDescription = location
    attributeSet.keywords = ["tennis", "scorelord", firstName, surname, handed, location, "\(itnLevel)"]
    attributeSet.thumbnailData = UIImageJPEGRepresentation(profileImage, 0.8)
    attributeSet.thumbnailData?.displayLayer(<#T##layer: CALayer##CALayer#>)
    return attributeSet
}

我也遇到了同样的问题。

假设您的图片具有透明背景,对我有用的是

 attributeSet.thumbnailData = UIImagePNGRepresentation(profileImage)  

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM