0
我試圖正方形UIImage
分成36倍的圖像(6×6幀)夫特2.2 - 分割的UIImage通過6X6小圖像
爲了我使用的UIImage
的延伸將圖像劃分,在半分割圖像然而,我無法找到讓圖像適合網格的方式。
有沒有一個簡單的方法來做到這一點?
extension UIImage {
var topHalf: UIImage {
return UIImage(CGImage: CGImageCreateWithImageInRect(CGImage, CGRect(origin: CGPoint(x: 0, y: 0), size: CGSize(width: size.width, height: size.height/2)))!, scale: 1, orientation: imageOrientation)
}
var bottomHalf: UIImage {
return UIImage(CGImage: CGImageCreateWithImageInRect(CGImage, CGRect(origin: CGPoint(x: 0, y: CGFloat(Int(size.height)-Int((size.height/2)))), size: CGSize(width: size.width, height: CGFloat(Int(size.height)-Int((size.height/2))))))!, scale: 1, orientation: imageOrientation)
}
var leftHalf: UIImage {
return UIImage(CGImage: CGImageCreateWithImageInRect(CGImage, CGRect(origin: CGPoint(x: 0, y: 0), size: CGSize(width: size.width/2, height: size.height)))!, scale: 1, orientation: imageOrientation)
}
var rightHalf: UIImage {
return UIImage(CGImage: CGImageCreateWithImageInRect(CGImage, CGRect(origin: CGPoint(x: CGFloat(Int(size.width)-Int((size.width/2))), y: 0), size: CGSize(width: CGFloat(Int(size.width)-Int((size.width/2))), height: size.height)))!, scale: 1, orientation: imageOrientation)
}
}
謝謝,我發現有點難以做它的數學。我設法找到第一個頂端使用'var topLeft1:UIImage返回UIImage(CGImage:CGImageCreateWithImageInRect(CGImage,CGRect(origin:CGPoint(x:0,y:0),size:CGSize(width:size.width/6 ,height:size.height/6)))!,scale:1,orientation:imageOrientation) }'但找不到下一個的方法 – SNos
我發現這個http://stackoverflow.com/questions/25607688/ ios-how-to-split-an-uiimage-into-parts ..也許會工作,如果我改變它迅速 – SNos