Swift for Xojo Developers : Part 7 - Graphics : Picture

Here is a PICTURE class … subclassed from yesterdays CANVAS class… it too is Experimental still


/* *********************************** */
/* ****                           **** */
/* **** P i c t u r e   C L A S S **** */
/* **** Super : CANVAS            **** */
/* ****                           **** */
/* *********************************** */
class Picture : Canvas {
    private var zWidth  : CGFloat = 0
    private var zHeight : CGFloat = 0
    init(pSize:CGSize) {
        // define specific context for Picture, must be done BEFORE initializing CANVAS superclass
        UIGraphicsBeginImageContextWithOptions(pSize,false,0.0)
        let picContext : CGContext = UIGraphicsGetCurrentContext()!
        super.init(context: picContext) // Initialize CANVAS superclass
        zWidth  = pSize.width
        zHeight = pSize.height
        //
        self.foreColor=UIColor.white
        self.fillRect(0,0,zWidth,zHeight)
        self.foreColor=UIColor.black
    }

    var image : UIImage {
        get {
            //    weak var img = UIGraphicsGetImageFromCurrentImageContext()
            let img = UIGraphicsGetImageFromCurrentImageContext()
            UIGraphicsEndImageContext()
            return img!
        }
    }

    var width  : CGFloat { get { return zWidth } }
    var height : CGFloat { get { return zHeight } }
}