nsimage

Storing an NSImage in a Core Data Model

What is the correct way to store an NSImage in a Core Data Model? I have assumed adding an Attribute to an Entity and giving it the Type "Binary" should work, but it is not working. I have a table with a column of NSImageCells and it is not showing anything. ...

NSImage rotation

I have a window with an subclass of NSView in it. Inside the view, I put an NSImage. I want to be able to rotate the image by 90 degrees, keeping the (new) upper left corner of the image in the upper left corner of the view. Of course, I will have to rotate the image, and then translate it to put the origin back into place. In Carbo...

How to efficiently assign NSStatusItem images and alternte images?

Let's say I have a code like this... - (id) init { ... self.myImage1 = [NSImage imageNamed:@"some_image_name"]; // setter retains ... } - (void) setStatusItemImage { [self.statusItem setImage:self.myImage1]; } I also want to animate the status item so I created 6 variants of the "updating" status item icon and loop it...

Rotating an NSImage with or without NSAffineTransform

I've got an NSImage being drawn on a subclass of NSView. In a previous question, I was helped to draw it upright in the upper left corner. Now, I want to be able to rotate the image. I have a button that increments a rotation variable %4, and then I multiply this by -90 to find the rotation angle. I then use an NSAffineTransform to rotat...

Create a padded, centered, scaled NSImage

I'm putting a fixed size icon based on an arbitrarily sized image into an NSOutlineView using an NSImageCell. NSImageCell will scale the image down nicely, but I can't find a way to add padding around the scaled image. The rows look ugly to my eye without padding. My first pass at fixing this problem was to create a new image of const...

Working with multi-page images in an NSImage

I'm working on an image viewer application (OSX) and currently it can load and view images, but I need to be able to view multi-page PDFs and TIFFs. I'll have next/previous page buttons, etc. Now, with PDF, I expect to use an NSPDFImageRep. This will let me set the current page and draw the current page etc. However, I don't see an NST...

NSBitmapImageRep and multi-page TIFFs

I've got a program that can open TIFF documents and display them. I'm using setFlipped:YES. If I'm just dealing with single page image files, I can do [image setFlipped: YES]; and that, in addition to the view being flipped, seems to draw the image correctly. However, for some reason, setting the flipped of the image doesn't seem ...

How to avoid a NSCachedImageRep

I'm working with an NSImage which comes from a PDF. When I initially create the image, it has only one NSImageRep and that is NSPDFImageRep. This is good. I can work with it. I can find out how many pages it has, and go to a specified page, and draw it, etc. The problem is that as soon as I turn my back, it gets turned into a NSCachedIm...

NSImageRep confusion

I have an NSImage that came from a PDF, so it has one representation, of type NSPDFImageRep. I do an image setDataRetained:YES; to make sure that it remains a NSPDFImageRep. Later, I want to change the page, so I get the rep, and set the current page. This is fine. The problem is that when I draw the image, only the 1st page comes out. ...

How can I load an NSImage representation of the icon for my application?

I have a custom icon file (MyApp.icns) set up for my Cocoa App. How can I access an NSImage representation of the icon from within my application? Something like the following would be perfect: NSImage * iconImage = [MyApplication defaultIconAsImage]; But I'm sure it isn't that easy :) I can, of course, get a path to the icon file a...

How do I get the icon of the user's Mac?

Using Objective-C and Cocoa, does anyone know how to get the icon for a user's computer (the one that shows under "Devices" and "Network" in Finder)? Not the harddisk icon, the actual one for a user's device. It ranges from a macbook icon to the mac pro "tower" icon to a Windows blue screen of death monitor icon. I've tried stuff along ...

How do I get the desktop icon used in Finder?

In Objective-c/Cocoa, how do I get the icon that Finder uses for the desktop (it looks like the black/pink nebula desktop image with a menu bar and dock). I tried this: NSImage *icon = [[NSWorkspace sharedWorkspace] iconForFileType: NSFileTypeForHFSTypeCode(kDesktopIcon)]; But all I get is a blue folder with a ghost...

Printing an NSImage

I'm migrating Cocoa-Java code to Cocoa + JNI since Cocoa-Java is deprecated. The code prints an image stored in a file. The new Cocoa code is basically: NSImage *image = [[NSImage alloc] initWithContentsOfFile:spoolFile]; if ( [image isValid] ) { NSImageView *view = [[NSImageView alloc] init]; [view setImage:image]; [view ...

How to get NSImage of generic folder icon on OS X 10.5 and 10.6

I'm writing a Cocoa application that displays the contents of an archive file in an NSOutlineView. I provide a custom icon for an NSBrowserCell in the outline column, and it works great, but I ran into a little snag — using [NSImage imageNamed:@"NSFolder"] returns the correct image (a generic folder icon) on 10.6, but on 10.5 it returns ...

Increase too-tight icon spacing in NSOutlineView

I'm writing a Cocoa application that displays the contents of an archive file in an NSOutlineView. I provide custom icons for an NSBrowserCell in the outline column, but I haven't been able to get the spacing quite right — the folder icon always appears too close to the disclosure triangle, as shown below. (FWIW, Versions and BetterZip b...

Clearing the alpha channel of an NSImage

It can be done by mallocing a temporary bitmap with 32bits per pixel and then clearing the alpha component with a for loop and and finally turn it back into a NSImage again. I suspect is can be done in a simpler way using a clever combination of NSColor and NSCompositingOperation. Or perhaps the image needs to be composited with itsel...

Is there a best way to size an NSImage to a maximum filesize?

Here's what I've got so far: NSBitmapImageRep *imageRep = [NSBitmapImageRep imageRepWithData: [file.image TIFFRepresentation]]; // Resize image to 200x200 CGFloat maxSize = 200.0; NSSize imageSize = imageRep.size; if (imageSize.height>maxSize || imageSize.width>maxSize) { // Find the aspect ratio CGFloat aspectRatio = imag...

Objective C - NSImageView, NSImage, NSBitmapImage rep object lifecycle?

I've built a video viewer that is a Safari plugin that displays video from networked devices. The viewer reads bitmap images, prepares them, and sets them on the NSImageView object as follows: NSBitmapImage *bmImg = [[NSBitmapImage alloc] initWithBitmapDataPlanes: . . .] NSImage *img = [[NSImage alloc] init]; [img addRepresentation:bmI...

Cocoa API Image Manipulation

Is there any way to do simple image manipulation like adjusting brightness, contrast, exposure, etc. using Cocoa? Something like NSImage? ...

NSImage imageNamed: for Mac Mini returns small icon instead of high-res

When using NSImage's imageNamed: method to get the icon for the current computer, if I'm running on a Mac Mini, then I get a low resolution image. If I run the same code from my MacBook, then I get a high-res icon like I'd expect. My code is as follows: NSImage *image; image = [NSImage imageNamed:@"NSComputer"]; [image setSize: NSMakeS...