如何在Swift 3.0中编写图像的纬度和经度?

时间:2017-04-01 09:09:38

标签: swift3

我按照下面的代码,它根本没有显示图像。那里有什么不对?我试图调试newimage节目nil。

我无法解决它。

func textOnImage(text: NSString, atPoint: CGPoint,capturedImage:UIImage?) -> UIImage? {

    if let capturedImage = capturedImage {

        // Setup the font specific variables
        let textColor = UIColor.white
        let textFont = UIFont(name: "Helvetica", size: 14)!

        // Setup the image context using the passed image

        let scale = UIScreen.main.scale

        UIGraphicsBeginImageContextWithOptions(capturedImage.size, false, scale)

        // Setup the font attributes that will be later used to dictate how the text should be drawn
        let textFontAttributes = [
            NSFontAttributeName: textFont,
            NSForegroundColorAttributeName: textColor,
            ] as [String : Any]

        // Create a point within the space that is as bit as the image

        let rect =  CGRect(x: atPoint.x, y: atPoint.y, width: capturedImage.size.width, height: capturedImage.size.height)

        // Draw the text into an image

        text.draw(in: rect, withAttributes: textFontAttributes)

        // Create a new image out of the images we have created
        let newImage = UIGraphicsGetImageFromCurrentImageContext()

        // End the context now that we have the image we need
        UIGraphicsEndImageContext()
//Pass the image back up to the caller
        return newImage!
    }
    return nil
}

1 个答案:

答案 0 :(得分:0)

包括以下行

Double::intValue

所以你的方法看起来像

Function<Double, Int>