2016-07-08 2 views
-1

Я пытаюсь сделать этот точный пример: Draw another image on a UIImage, но в Swift.Как я могу нарисовать изображение на другом UIImage, чтобы создать один UIImage

Я был бы очень признателен за любые объяснения или любую помощь в правильном направлении.

+0

, что вы пробовали в стрижа? –

+0

Пожалуйста, посмотрите [этот ответ] (https://stackoverflow.com/a/45915767/6536841). Благодаря !!! –

ответ

1

Это тот же код из статьи, но в быстрой надежде, что это работает для вас:

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() 
+0

Я нахожу этот сайт полезным для преобразования кода объектного кода в быстрый код: https://objectivec2swift.com/#/home/converter/ – Nate

Смежные вопросы