开发者

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];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜