on Mac OS X, an NSImage object is a high-level class for manipulating image data
Questions tagged [nsimage]
681 questions
81
votes
9 answers
How to save a NSImage as a new file
How can I save a NSImage as a new file (png, jpg, ...) in a certain directory?

burki
- 2,946
- 6
- 37
- 51
31
votes
6 answers
How to save PNG file from NSImage (retina issues)
I'm doing some operations on images, and after I'm done, I want to save the image as PNG on the disk. I'm doing the following:
+ (void)saveImage:(NSImage *)image atPath:(NSString *)path {
[image lockFocus] ;
NSBitmapImageRep…

Ludovic Landry
- 11,606
- 10
- 48
- 80
30
votes
5 answers
NSImage size not real size with some pictures?
I see that sometimes NSImage size is not real size (with some pictures) and CIImage size is always real. I was testing with this image.
This is source code which I wrote for testing:
NSImage *_imageNSImage = [[NSImage…

Justin Boo
- 10,132
- 8
- 50
- 71
28
votes
12 answers
How to resize NSImage?
I have an NSBitmapImageRep which is WxH size.
I create NSImage and call addRepresentation:. Then I need to resize the NSImage.
I tried setSize method but it doesn't work. What should I do?

hockeyman
- 1,141
- 6
- 27
- 57
27
votes
1 answer
Getting NSImage from CGImageRef
I am trying process an image in CoreGraphics and then return the processed image back to an NSImage for saving and displaying. I have ample resources on how to perform these functions in iOS but the helper methods seem to be missing in NSImage. In…

MobileOverlord
- 4,580
- 3
- 22
- 30
23
votes
6 answers
Get the correct image width and height of an NSImage
I use the code below to get the width and height of a NSImage:
NSImage *image = [[[NSImage alloc] initWithContentsOfFile:[NSString stringWithFormat:s]] autorelease];
imageWidth=[image size].width;
imageHeight=[image…

arachide
- 8,006
- 18
- 71
- 134
21
votes
1 answer
NSImage to NSData as PNG Swift
I am writing a Mac app based on an iOS app. The code below converts a UIImage to NSData to upload to Parse.com.
I would like to do the same for Mac but I do not seem to be able to convert it to NSData. What should I be doing?
Thanks
var image =…

Tom Coomer
- 6,227
- 12
- 45
- 82
21
votes
5 answers
Swift NSImage to CGImage
How can I convert a NSImage to CGImage in Swift? In Objective-C I did it like this:
- (CGImageRef)CGImage {
NSData *imageData = self.TIFFRepresentation;
CGImageSourceRef source = CGImageSourceCreateWithData((__bridge CFDataRef)imageData,…

Lupurus
- 3,618
- 2
- 29
- 59
19
votes
4 answers
How to draw a NSImage like images in NSButtons (with a deepness)?
Is there any way to draw an NSImage like images in NSButtons or other cocoa interface elements?
Here are examples:
Apple uses pdf's with black icons:

Flocked
- 1,898
- 2
- 36
- 57
18
votes
2 answers
Swift on MacOS - How to save NSImage to disk
I have the following code working:
let myImage = NSImage(named: "my-image.png")
filter.setValue(myImage, forKey: kCIInputImageKey)
filter.setValue(0.5, forKey: kCIInputIntensityKey)
let resultImage = filter.outputImage
How can I save the filtered…

Pono
- 11,298
- 9
- 53
- 70
18
votes
4 answers
How do I take a "screenshot" of an NSView?
I need to take the contents of an NSView and put them in an NSImage, for an experimental project. Is this possible? I did some Googling, tried two methods that I found - but they didn't really work. Any suggestions?

Debashis
- 199
- 1
- 1
- 4
18
votes
3 answers
Converting CIImage Into NSImage
I'm playing with the Core Image framework. As I understand, if I have an image (NSImage), it needs to be converted into CIImage, first. I can do that.
NSImage *im1 = [[NSImage alloc] initWithContentsOfFile:imagepath];
NSRect rect1;rect1.size.width…

El Tomato
- 6,479
- 6
- 46
- 75
16
votes
6 answers
Turning an NSImage* into a CGImageRef?
Is there an easy way to do this that works in 10.5?
In 10.6 I can use nsImage CGImageForProposedRect: NULL context: NULL hints: NULL
If I'm not using 1b black and white images (Like Group 4 TIFF), I can use bitmaps, but cgbitmaps seem to not like…

Brian Postow
- 11,709
- 17
- 81
- 125
16
votes
2 answers
How to composite several NSImages into one big image?
I have a collection of objects which describe an image-name, its size and it's X/Y location. The collection is sorted by "layers", so I can composite the images in a sort of painter's algorithm.
From this, I can determine the rectangle necessary to…

Olie
- 24,597
- 18
- 99
- 131
16
votes
3 answers
NSImage to NSBitmapImageRep
How to convert NSImage to NSBitmapImageRep? I have code:
- (NSBitmapImageRep *)bitmapImageRepresentation
{
NSBitmapImageRep *ret = (NSBitmapImageRep *)[self representations];
if(![ret isKindOfClass:[NSBitmapImageRep class]])
{
…

hockeyman
- 1,141
- 6
- 27
- 57