0

I have an NSImageView in a view that utilizes Core Animation. Prior to using Core Animation the image looks fine but now its blurry and low quality. If I let NSImageView have a bezel border the issue goes away but I need it to have no border. Had this happened to anyone else?

Blurry image

Imgae in the background with no border, same image in the front with a border.

Thanks

EDIT: I forgot to mention that the image is an icon file (ICNS) so it has various sizes. The bordered view loads the correct size and the transparent one loads the smallest and stretches it.

nosedive25
  • 2,477
  • 5
  • 30
  • 45
  • Are both of the views in the screenshot using Core Animation? – Peter Hosey Dec 10 '11 at 18:20
  • There both contained in the same view that uses Core Animation, The hierarchy is Content View (Window) -> My View (The one that uses Core Animation) and the NSImageView(s) – nosedive25 Dec 10 '11 at 18:59
  • Are you giving both image views the same image object? What's the `size` of that image object? What are the `frame`s of the image views? – Peter Hosey Dec 10 '11 at 19:16
  • The image is the same, set by CoreData in both. The frame of the blurry one is 211,281,195,195 (x,y,w,h) and the frame of the clear one is 345,214,29,198. The images size is 512Xx512. – nosedive25 Dec 10 '11 at 19:26
  • 29 points wide? Are you sure? Also, I know they're the same image, but are both image views getting the same NSImage object? – Peter Hosey Dec 10 '11 at 19:35
  • A typo im sorry it was supposed to be 198 and yes, they *should* be getting the same object. I can't say for certain because it's Core Data bindings giving the view the image, im never programmed an `NSImage` instance. – nosedive25 Dec 10 '11 at 19:39
  • If you have outlets to both image views, add code that will ask each image view for its `image` and log the image. That will tell you both whether they're the same object and what each object's `size` is. – Peter Hosey Dec 10 '11 at 19:49
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/5745/discussion-between-nosedive25-and-peter-hosey) – nosedive25 Dec 10 '11 at 20:02

2 Answers2

1

Although not the way I wanted to, I managed to create a fix for the issue. The issue seemed to be the way that NSImageView was drawing the image so I created a custom NSView subclass with support for the same bindings I used in my original image view. Im not sure why the blurry-ness happend in the beginning, but drawing the image by hand in an NSView seems to do the trick.

nosedive25
  • 2,477
  • 5
  • 30
  • 45
0

Your image may be drawing in a non-pixel-aligned way. Have you tried shifting it by a half pixel?

Apple has a good demonstration of this in the BlurryView app in their "Cocoa Tips and Tricks" sample code.

Cocoa Tips and Tricks

Francis McGrew
  • 7,264
  • 1
  • 33
  • 30