Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Read Image from Disk as Data Object

Read Image from Disk as Data Object
Thread Tools
Mac Enthusiast
Join Date: Sep 2000
Location: Vermont, USA
Status: Offline
Reply With Quote
Aug 30, 2005, 09:20 AM
 
I can't convert an image on disk to a NSData object and store the
data in my Core Data model.

I have a Core Data application where one of the entities has a data
attribute which I use to store an image. In the UI, the image is
displayed in an image view with bindings and an data unarchiver
formatter. If I drag and drop an image into the image well,
everything works fine.

My model class also has a method to receive the URL to an image and I
am trying to create the data object from the incoming URL without any
luck. I have tried dataWithContentsOfURL, creating an image and
converting that to a data object, but I always get the same error
when I set the data object to my model: +[NSUnarchiver
unarchiveObjectWithData:]: extra data discarded

Any help greatly appreciated. I tried on Apple's Cocoa list with no luck.
     
Forum Regular
Join Date: Feb 2005
Status: Offline
Reply With Quote
Aug 30, 2005, 04:11 PM
 
Can you supply any of your code?
     
Mac Enthusiast
Join Date: Sep 2000
Location: Vermont, USA
Status: Offline
Reply With Quote
Aug 30, 2005, 05:08 PM
 
Absolutely, it is quite simple.

This is my code:

-(void)setImagePathNSURL *)path {
NSLog([path className]); //just to check that I am actually getting a URL (could come from an AppleScript)
NSData *data = [NSData dataWithContentsOfURLath];
[self setValue:data forKey:@"image"];
}

The unarchiving error occurs when trying to display the image in an image view in the UI.

If I drag and drop the image on the image view, everything works fine.
     
   
Thread Tools
Forum Links
Forum 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
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:27 AM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2