var selectedImage: UIImage = "image.png"
let fileManager = NSFileManager.defaultManager()
var paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as String
var filePathToWrite = "\(paths)/SaveFile.png"
var imageData: NSData = UIImagePNGRepresentation(selectedImage)
fileManager.createFileAtPath(filePathToWrite, contents: imageData, attributes: nil)
var getImagePath = paths.stringByAppendingPathComponent("SaveFile.png")
if (fileManager.fileExistsAtPath(getImagePath))
{
println("FILE AVAILABLE");
//Pick Image and Use accordingly
var imageis: UIImage = UIImage(contentsOfFile: getImagePath)!
let data: NSData = UIImagePNGRepresentation(imageis)
}
else
{
println("FILE NOT AVAILABLE");
}
Hey Thanks for posting all of these swift examples, they are very helpful.
ReplyDeleteI have modified the code to support swift 2
ReplyDelete// Write to Documents Directory
let selectedImage: UIImage = profilePictureView.image!
let fileManager = NSFileManager.defaultManager()
let paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as String
let filePathToWrite = "\(paths)/User_Profile_Image.jpg"
// let imageData: NSData = UIImagePNGRepresentation(selectedImage)!
let jpgImageData = UIImageJPEGRepresentation(selectedImage, 1.0)
fileManager.createFileAtPath(filePathToWrite, contents: jpgImageData, attributes: nil)
// Check file saved successfully
let getImagePath = (paths as NSString).stringByAppendingPathComponent("User_Profile_Image.jpg")
if (fileManager.fileExistsAtPath(getImagePath))
{
print("FILE AVAILABLE");
//Pick Image and Use accordingly
// let imageis: UIImage = UIImage(contentsOfFile: getImagePath)!
// let data: NSData = UIImagePNGRepresentation(imageis)
}
else
{
print("FILE NOT AVAILABLE");
}
// End
i want to write csv file to document directory. Can u guide me in that.
ReplyDeletehow to pass the image to php server in swift 2
ReplyDeletehelped me out when other ways failed - thanks!
ReplyDeletehow to video and image parth store
ReplyDeleteHi,
ReplyDeleteI'm Niall Kehoe and I'm 12 years old. I'm the youngest iOS App developer in Europe. I'm trying to save an image with labels on top using this example. Unfortunately, when it saves an image it only saves the image you specified How can I get it to save with labels on top using this example?
I am saving using .writetoFile using different code. But it only saves in .pdf and when I try to recover it I can't : http://stackoverflow.com/questions/35560443/recovering-images-from-write-to-file-in-swift?noredirect=1#comment58810079_35560443 .
Image here: http://postimg.org/image/6m74hwtaj/39486ef0/
Please Help!
Lucky Club Casino site
ReplyDelete【ZALO:945084771】 ,casino site review & rating 【ZALO:945084771】,casino site review luckyclub.live & rating