diff --git a/PhotoBrowser.xcodeproj/project.pbxproj b/PhotoBrowser.xcodeproj/project.pbxproj index 0f41937..275fe8a 100644 --- a/PhotoBrowser.xcodeproj/project.pbxproj +++ b/PhotoBrowser.xcodeproj/project.pbxproj @@ -18,6 +18,7 @@ 4A7E8F3E224A16A6005B54C8 /* ImageContainerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A7E8F3D224A16A6005B54C8 /* ImageContainerView.swift */; }; 4A8A90962244C27D00A09C55 /* HighResolutionImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A8A90952244C27D00A09C55 /* HighResolutionImageView.swift */; }; 4A8EB7291CEF16020065EAB0 /* PBActionBarItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A8EB7281CEF16020065EAB0 /* PBActionBarItem.swift */; }; + 4ABA2F1F22B8929600DB589C /* UIImage+Resize.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4ABA2F1E22B8929600DB589C /* UIImage+Resize.swift */; }; 864F45E81E9F0A4900FF9215 /* Skitch.swift in Sources */ = {isa = PBXBuildFile; fileRef = 864F45E71E9F0A4900FF9215 /* Skitch.swift */; }; 86AEF7301EDEC8A000034DBA /* SkitchView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 86AEF72F1EDEC8A000034DBA /* SkitchView.swift */; }; A18117E01E83B66900F8CE8E /* CustomPhotoBroswerManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = A18117DF1E83B66900F8CE8E /* CustomPhotoBroswerManager.swift */; }; @@ -67,6 +68,7 @@ 4A7E8F3D224A16A6005B54C8 /* ImageContainerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageContainerView.swift; sourceTree = ""; }; 4A8A90952244C27D00A09C55 /* HighResolutionImageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HighResolutionImageView.swift; sourceTree = ""; }; 4A8EB7281CEF16020065EAB0 /* PBActionBarItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PBActionBarItem.swift; sourceTree = ""; }; + 4ABA2F1E22B8929600DB589C /* UIImage+Resize.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIImage+Resize.swift"; sourceTree = ""; }; 864F45E71E9F0A4900FF9215 /* Skitch.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Skitch.swift; sourceTree = ""; }; 86AEF72F1EDEC8A000034DBA /* SkitchView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SkitchView.swift; sourceTree = ""; }; A18117DF1E83B66900F8CE8E /* CustomPhotoBroswerManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CustomPhotoBroswerManager.swift; sourceTree = ""; }; @@ -182,6 +184,7 @@ C4C79EA02057808200C92C0C /* UIView+Frame.swift */, C4B64B622117E95300B29C5B /* UIViewController+Animation.swift */, 4A70A002225308A100DBD070 /* Kingfisher+CacheSerializer.swift */, + 4ABA2F1E22B8929600DB589C /* UIImage+Resize.swift */, ); path = Extensions; sourceTree = ""; @@ -456,6 +459,7 @@ 4A8EB7291CEF16020065EAB0 /* PBActionBarItem.swift in Sources */, C4B64B5D2117E90000B29C5B /* DismissAnimation.swift in Sources */, C4B64B652117EA6300B29C5B /* PBConstant.swift in Sources */, + 4ABA2F1F22B8929600DB589C /* UIImage+Resize.swift in Sources */, A18117E01E83B66900F8CE8E /* CustomPhotoBroswerManager.swift in Sources */, 86AEF7301EDEC8A000034DBA /* SkitchView.swift in Sources */, ); diff --git a/PhotoBrowser/Extensions/UIImage+Resize.swift b/PhotoBrowser/Extensions/UIImage+Resize.swift new file mode 100644 index 0000000..9800d90 --- /dev/null +++ b/PhotoBrowser/Extensions/UIImage+Resize.swift @@ -0,0 +1,21 @@ +// +// UIImage+Resize.swift +// PhotoBrowser +// +// Created by WangWei on 2019/6/18. +// Copyright © 2019 Teambition. All rights reserved. +// + +import UIKit + +extension UIImage { + func resize(to size: CGSize) -> UIImage { + UIGraphicsBeginImageContextWithOptions(size, false, 0) + let context = UIGraphicsGetCurrentContext() + draw(in: CGRect(origin: .zero, size: size)) + guard let cgImage = context?.makeImage() else { + return self + } + return UIImage(cgImage: cgImage) + } +} diff --git a/PhotoBrowser/PhotoPreview/PhotoPreviewController.swift b/PhotoBrowser/PhotoPreview/PhotoPreviewController.swift index 7703ec3..761e2c5 100644 --- a/PhotoBrowser/PhotoPreview/PhotoPreviewController.swift +++ b/PhotoBrowser/PhotoPreview/PhotoPreviewController.swift @@ -203,7 +203,8 @@ extension PhotoPreviewController { let pointSize = miniMapSize DispatchQueue.global().async { [weak self] in // downsample image to minimap size to reduce memory cost - let downsampled = image.kf.resize(to: pointSize, for: .aspectFit) + let targetSize = image.size.kf.resize(to: pointSize, for: .aspectFit) + let downsampled = image.resize(to: targetSize) DispatchQueue.main.async { self?.miniMap?.image = downsampled }