Re: Adding an image to a project
Re: Adding an image to a project
- Subject: Re: Adding an image to a project
- From: Vincenzo Morgante <email@hidden>
- Date: Thu, 15 Jul 2010 07:18:06 +0000 (GMT)
Perhaps I understand the problem...
NSString* imageName = [[NSBundle mainBundle] pathForResource:@"report" ofType:@"png"];if(imageName) { // print the path for resource}
The path for resource is not displayed because the object 'imageName' is nil.Why this object is nil?I added the file "report.png" to the folder Resources of my project: I will check whether the image is actually into WhateverApp.app/Contents/Resources/
Thanks a lot!
Vincenzo
--- Mer 14/7/10, Wim Lewis <email@hidden> ha scritto:
Da: Wim Lewis <email@hidden>
Oggetto: Re: Adding an image to a project
A: "Cocoa-Dev List" <email@hidden>
Cc: "Vincenzo Morgante" <email@hidden>
Data: Mercoledì 14 luglio 2010, 19:52
On Jul 14, 2010, at 10:01 AM, Vincenzo Morgante wrote:
> I wrote the following code, but it does not work: the program crashes...
> NSString* imageName = [[NSBundle mainBundle] pathForResource:@"image1" ofType:@"png"];
> IplImage *image = cvLoadImage([imageName UTF8String], ...);
That should work. Have you checked that 'imageName' actually holds the path to the image and is not nil? (If -pathForResource:ofType: fails, it will just return nil; and sending -UTF8String to nil will result in NULL, which perhaps cvLoadImage() does not check for.)
If you put the image into your project and add it to your application target, Xcode will automatically add it to a "Copy Files" build phase that places the image into WhateverApp.app/Contents/Resources/imagename.png. That is also the place that -pathForResource:ofType: will look for it. The link that Sam Reshu posted earlier explains this in more detail.
> Maybe the only solution is a copy pixel by pixel...
> If the source image is RGB, how can I get the pixel values? And what is the range of these values? Are there integer or double?
This would be unnecessarily slow and complex, but you could do it in a couple of ways:
- Look through the NSImage's representations array until you find an NSBitmapImageRep, and use -getBitmapDataPlanes: to get the data, and the other methods to figure out what format the data is in (lots of work, you need to handle many different possible pixel formats)
- Find the NSBitmapImageRep and use -getPixel:atX:y: (very slow!)
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please 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