 |
 |
Scrolling an NSImageView (NSScrollView?)
|
 |
|
 |
|
Senior User
Join Date: Jun 1999
Location: San Jose, CA
Status:
Offline
|
|
I have an image in a NSImage. I want to draw it out to my window, so right now I ust call:
[myImageView setImage: myImage];
However, this will either set it up cropped, or scaled. I want to be able to set it up cropped, but have it scrollable. Somewhat like Preview does, how you can have the image in a window, and if needed, scrollbars can be used to scroll around the image.
I cant seem to find what I need to do. Would I setup a NSScrollView, and then an NSImageView inside of that? Or is there something else I would need to do? Apple made NSTextViews so nice and easy, I wonder why they didn't do the same with NSImageViews?
Thanks,
Ben
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Jan 2000
Location: Los Altos, CA, USA
Status:
Offline
|
|
In Interface Builder, add a Custom View (NSView), set it to your variable, then click on the custom view and choose the menu item: Layout/Make Subviews Of/Scroll View.
Does that do what you want?
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Jun 1999
Location: San Jose, CA
Status:
Offline
|
|
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif">Originally posted by Brad Brack:
<strong>In Interface Builder, add a Custom View (NSView), set it to your variable, then click on the custom view and choose the menu item: Layout/Make Subviews Of/Scroll View.
Does that do what you want?</strong></font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">It might be on the right track, but no go.
I changed your instructions a bit. I creadted a custom view. But then made it an NSImageView (just making it an NSView wouldn't allow me to call setImage). I then set it to my variable, and chose the menu item: Layout/Make Subviews Of/Scroll View.
When I run my app, the image goes in place, but the scrollbars don't show up even if the image is to big. The scroll bar track is there, but no scroll bar
So any more help would be appriciated on this.
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Jun 1999
Location: San Jose, CA
Status:
Offline
|
|
*bump*
But also a question on the NSImage topic:
I read up on the compressions I can use (when I save a NSImage back out to disk as tiff), and I found the one I need:
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif">
NSTIFFCompressionCCITTFAX3
CCITT Fax Group 3 compression. It's for one-bit fax images sent over telephone lines.
</font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">However, when I do this:
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">myTiffData = [myImageToSave TIFFRepresentationUsingCompression:NSTIFFCompressi onCCITTFAX3 factor:nil];
[myTiffData writeToFile:@"/tmp/send/Output.tif" atomically:YES];</pre><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">The resulting image is a full color tiff (it looks exactly like the pdf file). From my understanding, I should have gotten a 1-bit, black and white image. What went wrong? Did I read into this too much, or am I not saving it with CCITT Fax Group 3 compression? Hopefully you know a bit about this, or someoen else that is readin gthis knows about the different tiff compressions.
Thanks,
Ben
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Sep 2000
Location: Tempe, AZ
Status:
Offline
|
|
When you set the image, do the following:
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">[myImageView setImage: myImage];
[myImageViw: setFrameSize: [myImage size]];</pre><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">
|
Geekspiff - generating spiffdiddlee software since before you began paying attention.
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Jun 1999
Location: San Jose, CA
Status:
Offline
|
|
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif">Originally posted by smeger:
<strong>When you set the image, do the following:
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">[myImageView setImage: myImage];
[myImageViw: setFrameSize: [myImage size]];</pre><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif"></strong></font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">Sweet! Thanks, just what I needed.
Now I have one last question. I have been looking through the NSImageView docs, and then the NSView docs, and I found the print method:
print:
- (void)print  id)sender
Opens the Print panel, and if the user chooses an option other than canceling, prints the receiver and all its subviews to the device specified in the Print panel.
But it only works on NSViews, not NSImageViews. Would I need to create a NSView, draw my NSImage into it, and then call print on that NSView? Or is there some easier way of doing it?
I am looking into creating a NSView (using initWithFrame), and I see I need to make an NSRect. However the only docs on NSRect I can find are java, and I need objective-c.
The height and width of my NSView need to be [myImage size].width by [myImage size].height
Thanks,
Ben
<small>[ 06-24-2002, 10:29 PM: Message edited by: kupan787 ]</small>
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Sep 2000
Location: Tempe, AZ
Status:
Offline
|
|
NSImageView is a subclass of NSView, so it inherits NSView's methods. The "print" method should "just work."
For NSRects, check out the "Functions" section at the bottom of the table of contents for Foundation. Link is
file://Developer/Documentation/Reference/ObjC_classic/Functions/FoundationFunctions.html . The function you want is NSMakeRect.
<small>[ 06-25-2002, 12:40 AM: Message edited by: smeger ]</small>
|
Geekspiff - generating spiffdiddlee software since before you began paying attention.
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Jun 1999
Location: San Jose, CA
Status:
Offline
|
|
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif">Originally posted by smeger:
<strong>NSImageView is a subclass of NSView, so it inherits NSView's methods. The "print" method should "just work."
</strong></font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">I thought it would as well, but when I tired I got this error:
*** -[NSImageView print]: selector not recognized
So i just tried creating a view, and going that way, but now I get this warning in Project Builder:
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif">
warning: `NSView' does not respond to `print'
</font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">and then if I ignore it, and try and run, I get this error:
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif">
lockFocus sent to a view whose window is deferred and does not yet have a corresponding platform window
</font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">myView is not onscreen, I thought i would be able to draw to a imaginary NSView for temp purposes. Here is the code I am using, let me know if you can spot anyhting wrong with it (I cant seem to find anything):
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">NSView *myView;
myView = [[NSView alloc] initWithFrame:NSMakeRect(0,0,[originalImage size].width, [originalImage size].height)];
[myView lockFocus];
[originalImage compositeToPoint:NSZeroPoint operation:NSCompositeCopy];
[myView unlockFocus];
[myView print];</pre><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">
<small>[ 06-25-2002, 01:21 AM: Message edited by: kupan787 ]</small>
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Sep 2000
Location: Tempe, AZ
Status:
Offline
|
|
You're using the "print" selector, which doesn't exist. The selector is "print:" (note the trailing colon). Here's the prototype:
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">- (void)print  id)sender</pre><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">The sender parameter is the object sending the print request. You can pass whatever you'd like, but generally, you pass, duh, the sender.
You're getting the log message about lockFocus because the view needs to be associated with a window before you can lock focus on it. If you don't want it to be in a window, you'll have to set up an offscreen one. See the lockFocusIfCanDraw selector for more info.
Finally, try to get in the habit of using the NSImage draw* selectors instead of the composite* selectors. The draw* selectors honor any rotations or transformations that have been applied to your view.
|
Geekspiff - generating spiffdiddlee software since before you began paying attention.
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Jun 1999
Location: San Jose, CA
Status:
Offline
|
|
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif">Originally posted by smeger:
<strong>When you set the image, do the following:
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">[myImageView setImage: myImage];
[myImageView: setFrameSize: [myImage size]];</pre><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif"></strong></font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">I just noticed something about this. myImage is a PDF, that is 3 pages long. Doig this sets me up with a scroller that only scrolls the first page, I don't ever see the second or third pages.
Should doing this allow me to scroll all 3 pages? Could it be that the setImage is only showing the first page?
After looking some more at the NSImage docs I see that:
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif">
Initializes the receiver, a newly allocated NSImage instance, with the contents of the file filename. Unlike initByReferencingFile:, this method opens filename and creates one or more image representations from its data.
</font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">So there is a PDF representation created I believe. Then I loked into NSPDFImageRep, and found setCurrentPage. So do I need to change the pages being displayed on my own? If so, is there a way to make it behave more like Preview does, and you can just continusly scroll from one page to the next?
Thanks,
Ben
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|