Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Soulstorm

macrumors 68000
Original poster
Feb 1, 2005
1,887
1
I have decided to make an application in Cocoa. The application will an image file, and will just add a text on top of it at the selected location.

I have managed to display the image using an NSImageView, and I have managed to display a selected text onto the image. I also wrote a very basic export feature (I will fix them all better afterwards).

But I have some problems:
1)I initially wanted to implement an NSTextView to allow the user to give the text he/shw wants and to add multiple lines of text. I couldn't do because every time I tried etracting the NSString from it (using the -string method) it gave me a nil string and the debugger came up. So I used an NSTextField instead. What can I do to fix that?
2)Most importantly: I want to find a way to resize large images. For smaller images, I have written code that resizes the image to fit the NSImageView. But that doesn't work for larger images. How can I scale them down to fit the NSImageView?
3)Last but not least, for large images, I want to be able to scroll the NSImageView so that I can see every inch of the image it displays. The way it is now, I can only see a small portion of the image that I am displaying.

If anyone could help me with these problems it would be greatly appreciated. I am attaching my project so far. I am warning you: It is my first project with images.
 

Attachments

  • cocoaki16.zip
    111.2 KB · Views: 168

Soulstorm

macrumors 68000
Original poster
Feb 1, 2005
1,887
1
1) It's stringValue not string.

NSTextView does not have a member named -stringValue, because it does not inherit from NSControl. Instead, it inherits from NSText, which contains a function named -string.
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
NSTextView does not have a member named -stringValue, because it does not inherit from NSControl. Instead, it inherits from NSText, which contains a function named -string.

Guess I should RTFM more then! I just assumed it was an NSControl somewhere down the line.

I'm on a Windows PC at work so I can't do much with your code here: I'll look at it when I'm at home...
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
See attached

1) Click on the NSImageView in IB and choose Layout->Make subview of->Scroll view

2) Click on the scroll view, shift-command-I and make both inner springs springy (auto-resize)

3) See the addition of setFrame to loadImageFromPath:

4) Replaced the text field with a text view. Works fine?

General comments:

Your design is all wrong. Your custom view is acting as a controller. You need to think MVC more...
 

Attachments

  • cocoaki16.zip
    59.9 KB · Views: 152

Soulstorm

macrumors 68000
Original poster
Feb 1, 2005
1,887
1
Actually it gets me a minor error. During your absence I fixed some of my problems. See what I have done.

EDIT: Fixed the link.
 

Attachments

  • cocoaki16.zip
    115.5 KB · Views: 145

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
Changing the frame size inside drawRect: is a really bad idea. This could cause dead-locks and crashes. My solution of setting the frame size when the image was loaded is better.
 

Soulstorm

macrumors 68000
Original poster
Feb 1, 2005
1,887
1
You are right. I will change it now. Thanks robbie for taking the time to look at my code.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.