-1
我想要做這個確切的例子:Draw another image on a UIImage但在Swift中。我如何繪製一個圖像到另一個UIImage來創建一個UIImage
我會非常感謝任何解釋或任何幫助在正確的方向這樣做。
我想要做這個確切的例子:Draw another image on a UIImage但在Swift中。我如何繪製一個圖像到另一個UIImage來創建一個UIImage
我會非常感謝任何解釋或任何幫助在正確的方向這樣做。
這是從文章但在迅疾希望相同的代碼這對你的作品:
var width: CGFloat
var height: CGFloat
var inputImage: UIImage
// input image to be composited over new image as example
// create a new bitmap image context at the device resolution (retina/non-retina)
UIGraphicsBeginImageContextWithOptions(CGSizeMake(width, height), true, 0.0)
// get context
var context: CGContextRef = UIGraphicsGetCurrentContext()
// push context to make it current
// (need to do this manually because we are not drawing in a UIView)
UIGraphicsPushContext(context)
// drawing code comes here- look at CGContext reference
// for available operations
// this example draws the inputImage into the context
inputImage.drawInRect(CGRectMake(0, 0, width, height))
// pop context
UIGraphicsPopContext()
// get a UIImage from the image context- enjoy!!!
var outputImage: UIImage = UIGraphicsGetImageFromCurrentImageContext()
// clean up drawing environment
UIGraphicsEndImageContext()
我覺得這個網站對於將objective-c代碼轉換爲swift代碼非常有用:https://objectivec2swift.com/#/home/converter/ – Nate
你在迅速試過嗎? –
請看看[這個答案](https://stackoverflow.com/a/45915767/6536841)。謝謝 !!! –