Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Apr 21, 2010, 09:38 AM   #1
AndyCodez
macrumors regular
 
Join Date: Aug 2009
Is this possible? UIImage > NSData > NSString > .txt file

I'm Exporting data to a text file and I'm wondering if anyone has done this.

Convert UIImage to NSData, represent the NSdata as nsstring, and then write the the string to the textfile. Then when reading the file back in its able to reverse that back into an image.

I could be misinterpreting how nsdata works but has anyone ever done this?
__________________
13" Macbook White, 2.00 ghz, 4 gig mem, 120g hd.
iphone 3g - 8gig.
Time Capsule 500g.
iFlashCardPro - Flash Cards
AndyCodez is offline   0 Reply With Quote
Old Apr 21, 2010, 10:04 AM   #2
jnic
macrumors 6502a
 
Join Date: Oct 2008
Location: Cambridge
It's certainly possible, but seems like overkill depending on what you're trying to achieve.

If you just want to cache images then why not just convert the UIImage to NSData and write it to NSUserDefaults?

Code:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSData *data = UIImagePNGRepresentation(image);
[defaults setObject:data forKey:@"key"];
Code:
NSData *data = [defaults dataForKey:@"key"];
UIImage *image = [UIImage imageWithData:data];
For export, you could use a JSON library for iPhone like SBJSON, or Base64-encode your images.

For converting NSString and NSData back and forth, you can use:

Code:
NSString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
Code:
NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];

Last edited by jnic; Apr 21, 2010 at 10:12 AM.
jnic is offline   0 Reply With Quote
Old Apr 21, 2010, 10:18 AM   #3
dejo
Demi-God (Moderator)
 
dejo's Avatar
 
Join Date: Sep 2004
Location: Colorado
Yeah, why the need to convert to string?
__________________
dejo is offline   0 Reply With Quote
Old Apr 21, 2010, 10:43 AM   #4
AndyCodez
Thread Starter
macrumors regular
 
Join Date: Aug 2009
Thanks for confirming it

Well in my application I'm enabling the user to export their decks of cards to google docs which is stored as Google Doc. Each card consists of question, answer, image, audio. so I'm building the file that would be able to be imported from Google docs. So I think i would need to make it a string to be able to add it to the file properly, (well the current way I am doing it.).

I'm not actually storing anything in the text file for the app storage this is all done in a sqlite database, this is just for exporting to Google Docs.

thanks for the responses!
__________________
13" Macbook White, 2.00 ghz, 4 gig mem, 120g hd.
iphone 3g - 8gig.
Time Capsule 500g.
iFlashCardPro - Flash Cards
AndyCodez is offline   0 Reply With Quote
Old Apr 21, 2010, 11:56 PM   #5
xStep
macrumors 68000
 
Join Date: Jan 2003
Location: Indianapolis, for an unknown time
From your NSData, I'd look at converting it using uuencode and decoding with uudecode. The other option is Base 64. This is common with e-mail applications.
xStep is offline   0 Reply With Quote
Old Jun 20, 2011, 10:38 AM   #6
franium
macrumors member
 
Join Date: Nov 2010
Quote:
Originally Posted by AndyCodez View Post
Thanks for confirming it

Well in my application I'm enabling the user to export their decks of cards to google docs which is stored as Google Doc. Each card consists of question, answer, image, audio. so I'm building the file that would be able to be imported from Google docs. So I think i would need to make it a string to be able to add it to the file properly, (well the current way I am doing it.).

I'm not actually storing anything in the text file for the app storage this is all done in a sqlite database, this is just for exporting to Google Docs.

thanks for the responses!
Hi, do you succeed in exporting image and text to google docs? I'm trying to use base64 encoding without success.
Thanks in advance,
Fran
franium is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
What does this mean and how is this possible waloshin Apple, Industry and Internet Discussion 5 Aug 19, 2011 09:16 AM
how is this possible? (printing to pdf file from windows-parallels) phuong Windows, Linux & Others on the Mac 14 Jun 29, 2011 04:42 PM
Is this possible that automator to unrar many files? hndn Mac Basics and Help 2 Mar 14, 2010 03:52 AM
How is this possibly being sold at this price?! andalusia MacBook Pro 16 Oct 29, 2009 08:11 AM
Is this possible? If so, is it legal? BrownPlopz Windows, Linux & Others on the Mac 4 Mar 30, 2008 06:29 PM


All times are GMT -5. The time now is 02:59 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

Privacy / DMCA contact / Affiliate and FTC Disclosure
Copyright 2002-2013, MacRumors.com, LLC