nsimage

Create and write paletted RGBA PNG using NSImage

ぐ巨炮叔叔 提交于 2019-12-01 14:08:43
I'm trying to create paletted PNG image (8-bit per pixel) that uses RGBA palette (32-bit per palette entry) using Cocoa framework*. I've tried few combinations for [NSBitmapImageRep initWithBitmapDataPlanes:…] method. It seems to create appropriate bitmap for bitsPerSample:2 bitsPerPixel:8 . However, when I try to write such bitmap with [NSBitmapImageRep representationUsingType:NSPNGFileType…] I get: libpng error: Invalid bit depth for RGBA image If I try other bit depths, then I get 32-bit per pixel (non-paletted) image. *) I know I could just use libpng , but that's not an answer I'm looking

Create and write paletted RGBA PNG using NSImage

99封情书 提交于 2019-12-01 12:43:47
问题 I'm trying to create paletted PNG image (8-bit per pixel) that uses RGBA palette (32-bit per palette entry) using Cocoa framework*. I've tried few combinations for [NSBitmapImageRep initWithBitmapDataPlanes:…] method. It seems to create appropriate bitmap for bitsPerSample:2 bitsPerPixel:8 . However, when I try to write such bitmap with [NSBitmapImageRep representationUsingType:NSPNGFileType…] I get: libpng error: Invalid bit depth for RGBA image If I try other bit depths, then I get 32-bit

Flip NSImage on both axes

∥☆過路亽.° 提交于 2019-12-01 04:24:35
I'm trying to flip an NSImage created with a NSImageBitmapRep representation. After some digging ( Flipping Quicktime preview & capture and Mirroring CIImage/NSImage ) I tried two ways via a CIImage and applying a scaling transformation with -1 for both factors. First using CIImage imageByApplyingTransform: NSBitmapImageRep *imgRep = ... CGImageRef cgi = [imgRep CGImage]; CIImage *cii = [CIImage imageWithCGImage:cgi]; CGAffineTransform at = CGAffineTransformTranslate(CGAffineTransformMakeScale(-1, -1), 0, 0); NSCIImageRep *ciiRep = [NSCIImageRep imageRepWithCIImage:[cii

Writing image metadata (EXIF/TIFF/IPTC) to image file in OS X

核能气质少年 提交于 2019-11-30 09:51:45
I am creating a photo editing app, and so far I've managed to read the metadata from image files successfully (after getting an answer to this question: Reading Camera data from EXIF while opening NSImage on OS X ). source = CGImageSourceCreateWithURL((__bridge CFURLRef)url, NULL); NSDictionary *props = (__bridge_transfer NSDictionary *) CGImageSourceCopyPropertiesAtIndex(source, 0, NULL); This copies all the metadata of the image file to a dictionary, and it works faily well. However, I couldn't find out how to write this metadata back to a newly created NSImage (or to an image file). Here is

how to change image resolution in objective-c

烈酒焚心 提交于 2019-11-30 07:33:57
I need to change the resolution of the existing image in objective-c just like Apple's Preview application Tools->Adjust Size...->Resolution. Please let me know the possible solutions. Here's a great sample I've used - http://weblog.scifihifi.com/2005/06/25/how-to-resize-an-nsimage/ From that sample, you can write resizedData to the file - and this will be a resized output in tiff format. UPDATE: here comes the NSImage category implementation, that allows to save NSImage instance with specified DPI: @interface NSImage (DPIHelper) - (void) saveAsImageType: (NSBitmapImageFileType) imageType

How to display animated GIF in Objective C on top of the layered View?

我的未来我决定 提交于 2019-11-30 05:24:49
I am trying to draw animated gif on my screen in mac OSX app . I used this code to insert the gif: I can see the Gif as 1 picture it doesn't animates only static picture :( what should I add to make it animated ? #import <Cocoa/Cocoa.h> #import <Quartz/Quartz.h>//for drawing circle #import "sharedPrefferences.h" @interface GenericFanSubView : NSView { NSColor * _backgroundColor; NSImageView* imageView; } - (void)setBackgroundColor :(NSColor*)color; - (void)insertGif1; - (void)insertGif2; - (void)insertGif3; @end #import "GenericFanSubView.h" #define PI 3.14285714285714 @implementation

How to draw a rounded NSImage

∥☆過路亽.° 提交于 2019-11-30 04:02:36
I am trying to create a NSImage or NSImageCell with rounded corners inside a NSTableView . I can't get anything to work. Here is the best I have so far inside my custom NSCell : - (void)drawInteriorWithFrame:(NSRect)frame inView:(NSView *)controlView { if (thumbnailLink) { NSURL *url = [NSURL URLWithString:thumbnailLink]; if (url) { NSRect imageFrame = [self _imageFrameForInteriorFrame:frame]; NSImage *image = [[NSImage alloc] initWithContentsOfURL:url]; [image setScalesWhenResized:YES]; [image setSize:NSMakeSize(IMAGE_HEIGHT, IMAGE_WIDTH)]; [NSGraphicsContext saveGraphicsState]; imageFrame =

Swift NSImage to CGImage

倖福魔咒の 提交于 2019-11-30 02:12:05
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, NULL); CGImageRef maskRef = CGImageSourceCreateImageAtIndex(source, 0, NULL); return maskRef; } Now I tried with: extension NSImage { var CGImage: CGImageRef { get { let imageData = self.TIFFRepresentation let source = CGImageSourceCreateWithData(imageData as CFDataRef, nil) let maskRef = CGImageSourceCreateImageAtIndex(source, UInt(0), nil) return maskRef; }

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

拜拜、爱过 提交于 2019-11-29 21:57:32
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 icon to a Windows blue screen of death monitor icon. I've tried stuff along the following lines: NSImage *icon = [[NSWorkspace sharedWorkspace] iconForFileType: NSFileTypeForHFSTypeCode(kComputerIcon)]; But that just returns the same icon all the time, obviously. I've also tried the iconForFile: method but I don't know of a file path to use as

How to draw a NSImage like images in NSButtons (with a deepness)?

我们两清 提交于 2019-11-29 18:53:25
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: omz If you simply want this effect to be applied when you use your own images in a button, use [myImage setTemplate:YES] . There is no built-in way to draw images with this effect outside of a button that has the style shown in your screenshots. You can however replicate the effect using Core Graphics. If you look closely, the effect consists of a horizontal gradient, a white drop shadow and a dark inner shadow (the latter is the most difficult).