Newbie: Encoding NSData to a string
Newbie: Encoding NSData to a string
- Subject: Newbie: Encoding NSData to a string
- From: Joao Lourenco <email@hidden>
- Date: Mon, 26 Mar 2007 07:05:53 +0200
Hello
I'm starting to learn Cocoa and would like to do the following
Read an image from a file
Encode the image as an "ascii" string
Send the image as an ASCII string in the body of a post message
This is the code I have so far:
Code:
NSImage *pictureToSend = [[NSImage alloc] initWithContentsOfFile:
filePath];
NSData *dataEncodedPicture = [pictureToSend TIFFRepresentation];
// do whatever you need to do to create and/or modify your NSImage
NSBitmapImageRep *imageRep = [NSBitmapImageRep
imageRepWithData:dataEncodedPicture];
NSDictionary *imageProps = [NSDictionary dictionaryWithObject:
[NSNumber numberWithFloat:0.9] forKey:NSImageCompressionFactor];
dataEncodedPicture = [imageRep representationUsingType:NSJPEGFileType
properties:imageProps];
NSString* stringEncodedPicture = [[NSString alloc] initWithData:
dataEncodedPicture encoding: NSUTF8StringEncoding];
NSLog(stringEncodedPicture);
All is well until: stringEncodedPicture = [[NSString alloc]
initWithData: dataEncodedPicture encoding: NSUTF8StringEncoding];
I am sure I am doing something wrong, I just don't know what.
Thanks for the help
Joao
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden