Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Saving and Loading UIImage from/to string

Using the http://www.ifans.com/forums/showthread.php?t=132024 post from another question i am allowing the user to enter a signature. When the user is finished entering the signature i want to save it away to the database. I want to know if it is possible to save a UIImage to a string at all? And than also reload the UIImage from the string?

Thanks in advance

like image 398
MattyD Avatar asked Jun 21 '26 12:06

MattyD


1 Answers

You should save your UIImage object as a Base64 string:

  1. Convert UIImage to NSData using UIImageJPEGRepresentation

  2. Convert NSData to Base64 string and then save the encoded string into database.

To load the image, reverse the process.

  1. Create a NSData object from saved Base64 encoded string.

  2. Use [UIImage initWithData] to initial an UIImage object.

like image 115
namk42c Avatar answered Jun 23 '26 01:06

namk42c