简体   繁体   中英

Xcode iPhone - How does one change image into text to manipulate?

Basically this is what I want to be able to do: I have a picture on my computer which is called image.png. If I change the file name by pushing F2 and change the name of it to image.txt, it changes the file extension and the image becomes a text document. When you open it you see all the image data which you can change (if you change it the picture doesn't come back however). You could edit, such as add a line after the image code that won't affect the image. After doing this, you can rename image.txt back to image.png and the picture will come back.

How do I get this to work coding wise? What I'm doing so far is saving my image using UIImagePNGRepresentation with the path being the documents directory with a.txt at the end of it. I then do NSString withcontentsoffile which is depreceated and it shows some code but it isn't the same as when I do it on my PC changing the extensions. If I do NSString with conentsoffile withencoding, the encoding makes nothing appear. I tried NSUTF8String....I'm not near the mac so I'm now exactly sure.

Basically I want to add text to an image (which if added at the bottom of the.txt will not mess up the image) and then change it back to an image and I can't seem to get this to work.

Need anymore info ask. I'll be checking back very often.

How about this?

NSData * imageData = UIImagePNGRepresentation(image);
NSMutableData * newData = [imageData mutableCopy];

NSString * string = @"Data to be appended";

[newData appendData:[string dataUsingEncoding:NSUTF8StringEncoding]];

UIImage * newImage = [[UIImage alloc] initWithData:newData];
[newData release];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM