Jonathan Eustace
Jonathan Eustace

Reputation: 2489

Save image as is in photo album using swift

I've written a steganography application in Swift v2. The workflow is simple : I open an image, I type in a message to save, I perform bitmanip to modify the least significant bit and then I save to photo album.

Problem is, iOS is running compression (I believe) on my image and some of the bits change.

How can I save my image directly to the photo album without having iOS change any of my bits? (I can post the code here, but there is a lot of it)

(this is a small snippet of the overall code)

 let imageRef = CGBitmapContextCreateImage(context);

 let newImage = UIImage(CGImage: imageRef!)
 UIImageWriteToSavedPhotosAlbum(newImage, nil, nil, nil)

Upvotes: 2

Views: 1065

Answers (1)

Jonathan Eustace
Jonathan Eustace

Reputation: 2489

It seems that I just needed to convert my newImage to be a UIImagePNGRepresenation.

 let imageRef = CGBitmapContextCreateImage(context);
 let newImage = UIImage(CGImage: imageRef!)
 let newImagePNG = UIImagePNGRepresentation(newImage)
 var saveableImage = UIImage(data: newImagePNG!)
 saveImage(saveableImage!)

Upvotes: 2

Related Questions