ios - Trying to save UiimageView but code is saving all of the page. In swift -
these 5 lines of code saving photo saving whole screen. save button acting screen on laptop. have uiimageview outlet imagepicker displays photo. want uimmmageview saved , not whole page.
my outlets name camerascreen. have tried insert in code not work. app takes photo , puts graphic on well.
here code
import uikit class camera: uiviewcontroller, uiimagepickercontrollerdelegate, uinavigationcontrollerdelegate, uitextfielddelegate { @iboutlet weak var camerascreen: uiimageview! var screenview: uiimageview! @ibaction func camera(_ sender: anyobject) { if uiimagepickercontroller.issourcetypeavailable(uiimagepickercontrollersourcetype.camera){ let imagepicker = uiimagepickercontroller() imagepicker.delegate = self imagepicker.sourcetype = uiimagepickercontrollersourcetype.camera; imagepicker.allowsediting = false self.present(imagepicker, animated: true, completion: nil)}} func imagepickercontroller(_ picker: uiimagepickercontroller, didfinishpickingimage image: uiimage!, editinginfo: [nsobject: anyobject]!){ camerascreen.image = image self.dismiss(animated: true, completion: nil); screenview = uiimageview() screenview.frame = cgrect(x:0, y: 0, width: self.view.frame.width, height: self.view.frame.height) let text = "java" let label = uilabel(frame: cgrect(x: 125, y: 400, width: self.view.frame.width, height: 300)) label.font = uifont(name: label.font.fontname, size: 200) label.textcolor = uicolor.blue label.alpha = 0.3 label.text = text self.view.addsubview(screenview) self.view.addsubview(label) } @ibaction func save(_ sender: anyobject) { let alert = uialertcontroller(title: "image saved", message: "", preferredstyle: .alert) let okay = uialertaction(title: "ok", style: .default, handler: nil) alert.addaction(okay) present(alert, animated: true, completion: nil) uigraphicsbeginimagecontext(self.view.frame.size) self.view.drawhierarchy(in: self.view.frame, afterscreenupdates: true) let photo = uigraphicsgetimagefromcurrentimagecontext() uigraphicsendimagecontext() uiimagewritetosavedphotosalbum(photo!, nil, nil, nil) }}
Comments
Post a Comment