Phase 4.F:微信截图分享 type=2 / 远端图分享 type=其它
按 msext gameController.m:637-678 字面行为,WechatShare 按 content.type 分发: - type=1 → shareLink(已有) - type=2 → captureScreenshot → JPEG 0.6 + thumb 0.4x → shareImage - type=其它 → downloadRemote(URL) → JPEG 0.9 + thumb 0.4x → shareImage 新增: - ImageProvider.scaledThumb(_:scale:):等价 msext FuncPublic imageByScalingAndCroppingForSize 0.4x 缩放;微信 SDK setThumbImage: 内部再压到 32KB - WeChatManager.ShareImage 结构 + shareImage(_:scene:) 异步包装 (WXImageObject + WXMediaMessage.setThumbImage,FIFO 串行复用 sharePending) 契约:与 type=1 一致,调成功 → sharesuccess 反向 callback(success/cancelled 都发);errCode=-2 → cancelled;其它 errCode → failed。 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
d9d9554d9f
commit
8e4c36d1c8
@@ -39,6 +39,22 @@ public enum ImageProvider {
|
||||
}
|
||||
}
|
||||
|
||||
/// 等比缩放图片用作微信分享的缩略图源。默认 0.4x 与 msext
|
||||
/// `imageByScalingAndCroppingForSize:CGSizeMake(w*0.4, h*0.4)` 等价
|
||||
/// (gameController.m:656 / 677 字面常量)。微信 SDK `setThumbImage:`
|
||||
/// 内部会再压缩至 32KB,外层只需把图像尺寸压低,避免传 4K 截图过 SDK 时
|
||||
/// 内部 JPEG 编码出超大缩略图。
|
||||
public static func scaledThumb(_ image: UIImage, scale: CGFloat = 0.4) -> UIImage {
|
||||
let target = CGSize(
|
||||
width: max(1, image.size.width * scale),
|
||||
height: max(1, image.size.height * scale)
|
||||
)
|
||||
let renderer = UIGraphicsImageRenderer(size: target)
|
||||
return renderer.image { _ in
|
||||
image.draw(in: CGRect(origin: .zero, size: target))
|
||||
}
|
||||
}
|
||||
|
||||
/// 下载远端 URL → UIImage。仅简单 URLSession 同步路径,无重试 / 缓存。
|
||||
public static func downloadRemote(_ urlString: String) async throws -> UIImage {
|
||||
guard let url = URL(string: urlString) else {
|
||||
|
||||
Reference in New Issue
Block a user