Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PickerConfiguration可否增加图片size的设定 #624

Closed
JerryFans opened this issue Feb 1, 2024 · 8 comments
Closed

PickerConfiguration可否增加图片size的设定 #624

JerryFans opened this issue Feb 1, 2024 · 8 comments

Comments

@JerryFans
Copy link

PickerConfiguration可否增加图片size的设定? 我看现在配置没有指定图片size的大小,比如1080p这种设定。直接获取即使不选原图,也是图片的原始size如果是拍照的尺寸太大啦。能否加个参数默认限制输出图片大小? 还是说有参数是我不知道如何设置?

@SilenceLove
Copy link
Owner

/// imageCompressionQuality:图片压缩参数
/// 获取 UIImage
let image = try await photoAsset.image(.init(imageCompressionQuality: 0.5))
/// 获取 URL
let imageURL = try await photoAsset.url(.init(imageCompressionQuality: 0.5))

@SilenceLove
Copy link
Owner

SilenceLove commented Feb 2, 2024

public struct PickerResult {
    
    /// 已选的资源
    public let photoAssets: [PhotoAsset]
    
    /// Whether to select the original image
    /// 是否选择的原图
    public let isOriginal: Bool
    
    /// 原图未选中获取 URL 时的压缩参数
    public var compression: PhotoAsset.Compression? = .init(
        imageCompressionQuality: 0.6,
        videoExportParameter: .init(
            preset: .ratio_960x540,
            quality: 6
        )
    )
}

也可以根据选择的 PickerResult 设置压缩参数 compression

@JerryFans
Copy link
Author

imageCompressionQuality 应该只是图片压缩的质量吧, 有办法指定图片的Size么? 现在拿出来拍照的太大了

@SilenceLove
Copy link
Owner

可以缩小size,设置0.5 size会缩小一倍

@JerryFans
Copy link
Author

可以缩小size,设置0.5 size会缩小一倍

了解了。目前缩小size就是用这个参数来指定倍率, 暂时没有api支持指定一个分辨率(CGSize)是么。

@SilenceLove
Copy link
Owner

目前没有,后面会加上个指定imageSize

SilenceLove added a commit that referenced this issue Feb 16, 2024
@SilenceLove
Copy link
Owner

最新版已加

/// targetSize: 指定imageSize
/// targetMode: 裁剪模式
let image = try await photoAsset.image(targetSize: .init(width: 200, height: 200), targetMode: .fill)

@JerryFans
Copy link
Author

Nice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants