Created
June 12, 2018 07:20
-
-
Save bob910078/0dba4a874d14d9ebc6d942186ecc1427 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override func viewDidAppear(_ animated: Bool) { | |
if let img = UIImage(named: "Sonic") { | |
let considerationPaperSize = CGSize(width: 1800, height: 2400) | |
let outputImage = self.allocate(image: img, inPhotoPaper: considerationPaperSize) | |
Thread.updateUI(byType: .async) { | |
self.myImage.image = outputImage | |
} | |
} | |
} | |
func allocate(image: UIImage, inPhotoPaper paper: CGSize) -> UIImage? { | |
let imageW: Int = Int(image.size.width) | |
let imageH: Int = Int(image.size.height) | |
let widthQuantity: Int = Int(paper.width / image.size.width) | |
let heightQuantity: Int = Int(paper.height / image.size.height) | |
print("Drawing origin points count [wide, height] : [\(widthQuantity), \(heightQuantity)]") | |
UIGraphicsBeginImageContext(paper) | |
for indexX in 0...widthQuantity-1 { | |
for indexY in 0...heightQuantity-1 { | |
print("add image into point : (\(indexX), \(indexY))") | |
let point = CGPoint(x: imageW * indexX, y: imageH * indexY) | |
let size = CGSize(width: image.size.width, height: image.size.height) | |
image.draw(in: CGRect(origin: point, size: size)) | |
} | |
} | |
return UIGraphicsGetImageFromCurrentImageContext() | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment