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

Reply
 
Thread Tools Search this Thread Display Modes
Old Nov 4, 2007, 04:25 AM   #1
Soulstorm
macrumors 68000
 
Soulstorm's Avatar
 
Join Date: Feb 2005
CCImage Initialization Problems

I am trying to load an image and display it into an NSImageView. The image is located somewhere in my computer. But I am having some problems. Here is my code.

Code:
-(void)loadImageFromPath:(NSString *)aPath
{
	NSURL *url = [NSURL fileURLWithPath:[aPath stringByStandardizingPath]];
	NSLog([url absoluteString]);
	CIImage *currentImage = [CIImage imageWithContentsOfURL:url];
	if (currentImage == nil) {
		NSLog(@"failed to initialize the image");
	}
	
	mainImage = currentImage;
}
It seems that the image is not initialized. Does anyone know why? I am assuming there is something wrong with my NSUrl methods...
Soulstorm is offline   0 Reply With Quote
Old Nov 4, 2007, 04:37 AM   #2
robbieduncan
Moderator
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
That looks like it should work. Can you give us an example aPath that does not work?
robbieduncan is offline   0 Reply With Quote
Old Nov 4, 2007, 07:20 AM   #3
kainjow
Moderator emeritus
 
kainjow's Avatar
 
Join Date: Jun 2000
Wouldn't you have to convert the CIImage to NSImage for the NSImageView?
kainjow is offline   0 Reply With Quote
Old Nov 4, 2007, 02:07 PM   #4
Soulstorm
Thread Starter
macrumors 68000
 
Soulstorm's Avatar
 
Join Date: Feb 2005
Quote:
Wouldn't you have to convert the CIImage to NSImage for the NSImageView?
That's not necessary. Apple's examples do not do it this way.

I am enclosing the faulty project. I hope you figure out what I am doing wrong. I am using XCode 3.0, but I don't see any reason this shouldn't work on earlier versions.
Attached Files
File Type: zip Image Filterizer.zip (37.7 KB, 19 views)
Soulstorm is offline   0 Reply With Quote
Old Nov 4, 2007, 02:29 PM   #5
Eraserhead
macrumors G4
 
Eraserhead's Avatar
 
Join Date: Nov 2005
Location: UK
Well it works for me with a .png file (instead of iTunes.pdf), as long as the line
Code:
//mainImage = [CIImage imageWithContentsOfURL:[NSURL fileURLWithPath:@"~/Desktop/242719UAcy_w.jpg"]];
Is removed.

Though you have no problems in this situation you may need to use retain/release, unless you are using Objective C 2.0, but I know nothing on that.
Eraserhead is offline   0 Reply With Quote
Old Nov 4, 2007, 09:39 PM   #6
kainjow
Moderator emeritus
 
kainjow's Avatar
 
Join Date: Jun 2000
Quote:
Originally Posted by Soulstorm View Post
That's not necessary. Apple's examples do not do it this way.
Interesting. Has NSImageView supported CIImage since 10.4, or is this new in 10.5?

/too lazy to look it up
kainjow is offline   0 Reply With Quote
Old Nov 5, 2007, 02:56 AM   #7
Soulstorm
Thread Starter
macrumors 68000
 
Soulstorm's Avatar
 
Join Date: Feb 2005
Quote:
Originally Posted by kainjow View Post
Interesting. Has NSImageView supported CIImage since 10.4, or is this new in 10.5?

/too lazy to look it up
Actually, NSView supported CIImage objects. Tiger definitely had support, since before upgrading, I was looking at Apple's examples and they used an NSView to display CIImage objects.

Since NSImageView is a subclass of NSView, it implements all support for CIImage, too. Oh, and the problem was solved. There was nothing wrong with the code. It just doesn't work with pdf documents.
Soulstorm is offline   0 Reply With Quote
Old Nov 5, 2007, 11:43 AM   #8
Soulstorm
Thread Starter
macrumors 68000
 
Soulstorm's Avatar
 
Join Date: Feb 2005
I have another problem right now. When I try to load an image from an arbitrary location, it will crash. It won't tell me why. Can you check it?
Attached Files
File Type: zip Image Filterizer.zip (41.2 KB, 13 views)
Soulstorm is offline   0 Reply With Quote
Old Nov 5, 2007, 12:45 PM   #9
kainjow
Moderator emeritus
 
kainjow's Avatar
 
Join Date: Jun 2000
Quote:
Originally Posted by Soulstorm View Post
Actually, NSView supported CIImage objects. Tiger definitely had support, since before upgrading, I was looking at Apple's examples and they used an NSView to display CIImage objects.

Since NSImageView is a subclass of NSView, it implements all support for CIImage, too. Oh, and the problem was solved. There was nothing wrong with the code. It just doesn't work with pdf documents.
Oh, you're just drawing the CIImage directly. I thought you were using the NSImageView setImage: method with a CIImage.

Quote:
Originally Posted by Soulstorm View Post
I have another problem right now. When I try to load an image from an arbitrary location, it will crash. It won't tell me why. Can you check it?
Do you have GC enabled? If you do, you are using release/retain unnecessarily. If you don't, you aren't using correct memory management.
kainjow is offline   0 Reply With Quote
Old Nov 5, 2007, 01:02 PM   #10
Soulstorm
Thread Starter
macrumors 68000
 
Soulstorm's Avatar
 
Join Date: Feb 2005
Quote:
Originally Posted by kainjow View Post
Do you have GC enabled? If you do, you are using release/retain unnecessarily. If you don't, you aren't using correct memory management.
That makes sense. Although I still cannot find out what the error is. I am not using Carbage Collection.
Soulstorm is offline   0 Reply With Quote
Old Nov 5, 2007, 01:08 PM   #11
kainjow
Moderator emeritus
 
kainjow's Avatar
 
Join Date: Jun 2000
Quote:
Originally Posted by Soulstorm View Post
That makes sense. Although I still cannot find out what the error is. I am not using Carbage Collection.
Well when you assign mainImage, you don't retain it, and then you use it in drawRect:. So that could be the problem.
kainjow is offline   0 Reply With Quote
Old Nov 5, 2007, 01:22 PM   #12
Eraserhead
macrumors G4
 
Eraserhead's Avatar
 
Join Date: Nov 2005
Location: UK
Quote:
Originally Posted by kainjow View Post
Well when you assign mainImage, you don't retain it, and then you use it in drawRect:. So that could be the problem.
As I mentioned before .
__________________
If they have to tell you every day they are fair you can bet they arent, if they tell you they are balanced then you should know they are not - Don't Hurt me
Eraserhead is offline   0 Reply With Quote
Old Nov 5, 2007, 03:58 PM   #13
Soulstorm
Thread Starter
macrumors 68000
 
Soulstorm's Avatar
 
Join Date: Feb 2005
Quote:
Originally Posted by kainjow View Post
Well when you assign mainImage, you don't retain it, and then you use it in drawRect:. So that could be the problem.
That solved my problem. So, that produced a question in my tiny brain

Why do I need to retain it? When I create the CIImage object, it has a retain count of 1. When does it get released? At the end og the loadImageFromPath: method?

In general, when do autorelease objects get released in cocoa applications? In Foundation tools, they get released when the pool is released. But in Cocoa applications, where are those invisible pools?
Soulstorm is offline   0 Reply With Quote
Old Nov 5, 2007, 05:32 PM   #14
robbieduncan
Moderator
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
Quote:
Originally Posted by Soulstorm View Post
That solved my problem. So, that produced a question in my tiny brain

Why do I need to retain it? When I create the CIImage object, it has a retain count of 1. When does it get released? At the end og the loadImageFromPath: method?

In general, when do autorelease objects get released in cocoa applications? In Foundation tools, they get released when the pool is released. But in Cocoa applications, where are those invisible pools?
In Cocoa there is an autorelease pool automatically in place for the main thread (you need to create your own for other threads). This is flushed at the end of each run loop. Object created by convenience methods (class level methods that create an object in one call) are auto-released. Objects created by alloc/init are not.
robbieduncan is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
[ipnone 5S] Skip touch id initialization during setup stage meinD iPhone 4 Mar 21, 2014 02:39 PM
Can someone help with an Initialization Error? Johnsa69 Mac Applications and Mac App Store 6 Sep 6, 2013 08:57 AM
Multi-monitor initialization sequence in ML cjd Mac Pro 2 Jun 1, 2013 07:47 PM
External Hard Drive Initialization bbhuang OS X 1 Dec 26, 2012 10:05 AM
Unprompted Automatic Synch on Initialization of IPhone? Happy2 iPhone Tips, Help and Troubleshooting 0 Jun 21, 2012 09:05 AM

Forum Jump

All times are GMT -5. The time now is 09:31 AM.

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

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC