• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Question about NSImage and NSImageView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Question about NSImage and NSImageView


  • Subject: Question about NSImage and NSImageView
  • From: Joe Chan <email@hidden>
  • Date: Mon, 15 Nov 2004 22:02:12 -0500

I have some questions about how to properly use NSImage and NSImageView. This is the situation I have:

I have a JPEG that is 740x1100 at 300dpi. I loaded it into a NSImage object, and as expected, the NSImageRep shows that the size is 177.6x264. I want to draw this image into a window at pixel dimension, basically ignoring the image's original dpi, so I have this code:

NSWindow *wind = [self window];
NSRect rect = [wind frame];
NSImageRep *rep = [image bestRepresentationForDevice: [wind deviceDescription]];
NSSize newSize = {[rep pixelsWide], [rep pixelsHigh]};
rect.size = newSize;
[image setSize: newSize];
[wind setFrame: rect display: NO];
rect.origin.x = rect.origin.y = 0;
[imageView setFrame: rect];


Which works as expected: the window is displays the entire picture at pixel dimensions. However, if I wrap the NSImageView in a NSScrollView, this code doesn't work as before, instead, the image is now drawn at the size indicated by NSImageRep (177.6x264). To get it to behave the same, I had to set the NSImageRep's size to 740x1100 instead.

Now come the questions:

- What is the correct way for me to display the image in some arbitrary dimension? Use [NSImageView setFrame:] and let NSImage fill the frame, or use [NSImageRep setSize:] to change the size of the image? And why doesn't the first method work when it's in a NSScrollView?

- Is NSImageRep roughly equal to a GWorld in the good old days? For example, can I change the interpolation and anti-alias setting and create a new NSImageRep at new dimensions, and stick the new one into the same NSImage?

Thanks

--
Joe Chan

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Question about NSImage and NSImageView
      • From: "M. Uli Kusterer" <email@hidden>
  • Prev by Date: Re: Best way to catch signals in a Cocoa app
  • Next by Date: Re: Custom NSToolbarItem
  • Previous by thread: RE: newbie memory question
  • Next by thread: Re: Question about NSImage and NSImageView
  • Index(es):
    • Date
    • Thread