Re: Adding an image to a project
Re: Adding an image to a project
- Subject: Re: Adding an image to a project
- From: Wim Lewis <email@hidden>
- Date: Wed, 14 Jul 2010 10:52:13 -0700
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