nsimage

I need to zero out one of the color channels in an NSImage, whats the right way to do this?

时光怂恿深爱的人放手 提交于 2019-12-08 04:18:22
问题 I want to achieve the same result as if I were in photoshop and turned off one of the channels. I was about to try to loop through every pixel changing colors. Is there a better way to do this? 回答1: Use Core Image's Color Matrix filter. The array of vectors can be bewildering, but it's very powerful. In your case, you'll want to set the vector for the channel you want to turn off to all-zeroes. Obviously, this will only work for RGB images, since Core Image only works for RGB images. You can

NSImage transparency

喜欢而已 提交于 2019-12-08 04:12:41
问题 I'm trying to set a custom drag icon for use in an NSTableView. Everything seems to work but I've run into a problem due to my inexperience with Quartz. - (NSImage *)dragImageForRowsWithIndexes:(NSIndexSet *)dragRows tableColumns:(NSArray *)tableColumns event:(NSEvent *)dragEvent offset:(NSPointPointer)dragImageOffset { NSImage *dragImage = [NSImage imageNamed:@"icon.png"]; NSString *count = [NSString stringWithFormat:@"%d", [dragRows count]]; [dragImage lockFocus]; [dragImage

Issues with NSImage add representation in Retina Display

故事扮演 提交于 2019-12-08 02:04:21
问题 I have two CGImageRef, imgRef1 and imgRef2. I want to create a NSImage with two representations of those CGImageRefs (for creating NSCursor). For this I used BitMapRepresentation initWithCGImage method and then added those representations to NSImage. But this doesn't work. Then I tried creating NSImage from imageRef1 and imgRef2 and then generated NSData from those NSImage's using TiffRepresentation and then added those representations to finally get the NSImage. But again this is giving low

NSImage rotation

怎甘沉沦 提交于 2019-12-06 16:40:18
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 Carbon, I found CGContextRotateCTM which does what I want . However, I can't find the right call in ObjC. setFrameCenterRotation doesn't seem to do anything, and in setFrameRotation, I can't seem to figure out where the origin is, so I can approprately translate. It

Cocoa - problem with this code using NSBundle

亡梦爱人 提交于 2019-12-06 16:17:54
问题 It was suggested that I use this line of code to call an image from my resources folder/project bundle. I also see it being used exactly like this on many different website tutorials. NSBundle *mb=[NSBundle mainBundle]; NSString *fp=[mb pathForResource:@"topimage" ofType:@"PNG"]; NSImage *image=[NSImage initWithContentsOfFile:fp]; HOWEVER, I am receiving the following warning: NSImage may not respond to +initWithContentsOfFile+ The documentation for NSImage shows that initWithContentsOfFile

Creating an ICNS Programmatically : “Unsupported Image Size”

心已入冬 提交于 2019-12-06 14:34:52
I'm trying to create an ICNS (including a 1024x1024 image) programmatically. Currently I'm creating an NSImage , then I create CGImageRef objects with the appropriate resolution, finally I'm adding them to an icon by using CGImageDestinationAddImage() . Peter Hosey has helped me create '@2x' images already, but the sizes of the images don't wanna be set. This is the code (still a bit messy, sourcefile represents the path to the image) : NSSize sizes[10]; sizes[0] = NSMakeSize(1024,1024); sizes[1] = NSMakeSize(512,512); sizes[2] = NSMakeSize(512,512); sizes[3] = NSMakeSize(256,256); sizes[4] =

Rounded NSImage corners in a NSButtonCell

走远了吗. 提交于 2019-12-06 14:15:43
问题 I have a NSMatrix with a couple of NSButtons in it which have no Text but are only images. One of the images is downloaded from the internet and I would like to have it rounded corners in my OS X application. I found one answer which nearly is what I was looking for: How to draw a rounded NSImage but sadly it acts crazy when I use it: // In my NSButtonCell subclass - (void)drawImage:(NSImage*)image withFrame:(NSRect)imageFrame inView:(NSView*)controlView { // [super drawImage:image withFrame

Hiding the lupe icon of a NSSearchField

故事扮演 提交于 2019-12-06 13:50:36
I’m using a NSSearchField (not subclassed). When it’s not focused, the placeholderString is centered. But the lupe icon on the left appears a bit offset, so in fact the whole thing appears not to be centered. Is it possible to hide the lupe icon? There is not any direct access to the icon, so that a workaround is first access to the NSSearchField cell (casted as shown), and afterwards access to its button cell. self in this example is an instance of NSSearchField [(NSButtonCell *)[(NSSearchFieldCell *)self.cell searchButtonCell] setTransparent:YES]; Deafault Search Field: Hidden/Transparent

Issues with NSImage add representation in Retina Display

馋奶兔 提交于 2019-12-06 13:22:36
I have two CGImageRef, imgRef1 and imgRef2. I want to create a NSImage with two representations of those CGImageRefs (for creating NSCursor). For this I used BitMapRepresentation initWithCGImage method and then added those representations to NSImage. But this doesn't work. Then I tried creating NSImage from imageRef1 and imgRef2 and then generated NSData from those NSImage's using TiffRepresentation and then added those representations to finally get the NSImage. But again this is giving low res Image in retina displays. HEre is the sample code: (Any help would be appreciated) float aHotSpotX

How to draw a colored border around NSImage?

扶醉桌前 提交于 2019-12-06 01:04:06
问题 I did some research but all the answers I got were for iOS, how can I draw a colored border around NSImage in OSX app? I tried using imageView property of NSImage to set it's border width and color, but it doesn't seem to be working... Any kind of help is highly appreciated! 回答1: Try like this without creating subclass also it is possible. Also you can set the width ans radius accordingly:- [imgView setWantsLayer:YES]; imgView.layer.borderWidth = 1.0; imgView.layer.cornerRadius = 8.0; imgView