nsimage

Display image in a cocoa status app

瘦欲@ 提交于 2019-12-05 19:02:44
问题 Hi I developed a cocoa status app. when I put a long title for example , it can't be shown and if i put an image as icon too it can't be shown , but if i put a small title it works correctly. How can I fix this problem and make the image shown? statusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength] retain]; [statusItem setMenu:menu]; //[statusItem setTitle:@"Notif "]; [statusItem setImage:[NSImage imageNamed:@"image"]]; [statusItem setHighlightMode:YES];

Resize CGImageRef without anti-liasing

可紊 提交于 2019-12-05 01:58:28
问题 I am trying to resize a 10x10 pixel CGImageRef, captured like this: CGImageRef imageRef = CGImageCreateWithImageInRect(screenShot, CGRectMake(mouseLoc.x-5, screen_height-mouseLoc.y-5, 10, 10)); CGContextRef mainViewContentContext = CGBitmapContextCreate (NULL, maskImage.size.width, maskImage.size.height, 8, maskImage.size.height*4, colorSpace, kCGImageAlphaPremultipliedFirst); CGContextDrawImage(mainViewContentContext, NSMakeRect(0,0, maskImage.size.width, maskImage.size.height), imageRef);

Trying to resize an NSImage which turns into NSData

走远了吗. 提交于 2019-12-05 01:35:51
问题 I have an NSImage which I am trying to resize like so; NSImage *capturePreviewFill = [[NSImage alloc] initWithData:previewData]; NSSize newSize; newSize.height = 160; newSize.width = 120; [capturePreviewFill setScalesWhenResized:YES]; [capturePreviewFill setSize:newSize]; NSData *resizedPreviewData = [capturePreviewFill TIFFRepresentation]; resizedCaptureImageBitmapRep = [[NSBitmapImageRep alloc] initWithData:resizedPreviewData]; saveData = [resizedCaptureImageBitmapRep

How to composite several NSImages into one big image?

左心房为你撑大大i 提交于 2019-12-04 16:29:40
问题 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 hold all of the images, so now what I want to do is: Create some sort of buffer to hold the result (The NS equivalent of what iPhoneOS calls UIGraphicsContext.) Draw all the images into the buffer. Snag a new NSImage out of the composited result of

How to create a ICNS icon programmatically?

好久不见. 提交于 2019-12-04 12:06:31
OK this is what I want : Take some NSImage s Add them to an ICNS file Save it This is what I've done so far (purely as a test) : - (CGImageRef)refFromImage:(NSImage*)img { CGImageSourceRef source; source = CGImageSourceCreateWithData((CFDataRef)[img TIFFRepresentation], NULL); CGImageRef maskRef = CGImageSourceCreateImageAtIndex(source, 0, NULL); return maskRef; } - (void)awakeFromNib { NSImage* img1 = [NSImage imageNamed:@"image1"]; NSImage* img2 = [NSImage imageNamed:@"image2"]; NSLog(@"%@",img1); CGImageRef i1 = [self refFromImage:img1]; CGImageRef i2 = [self refFromImage:img2]; NSURL

Getting bounds of an NSImage within an NSImageView

妖精的绣舞 提交于 2019-12-04 03:35:09
I've got an NSImageView that takes up the full extent of a window. There's no border to the image view, and its set to display in the lower left. So this means that the origin of the view matches the origin of actual image, no matter how the window is resized. Also, the image is much larger than what I can reasonably fit at full scale on the screen. So I also have the imageview set to proportionally scale down the size of the image. However, I can't seem to find this scale factor anywhere. My ultimate goal is to map a mouse down event into actual image coordinates. To do this, I think I need

Getting NSImage from CGImageRef

末鹿安然 提交于 2019-12-03 22:14:32
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 iOS the class method is imageWithCGImage: , how can you do this in Mac OS? The matching method in NSImage is initWithCGImage:size: . The second argument takes the image's size in points. The factor between the size in pixels (of the CGImage) and the size in points is the scale factor. So, for example, if you have a 100×100px CGImage, and pass a size

NSImage to NSBitmapImageRep

半城伤御伤魂 提交于 2019-12-03 17:13:44
问题 How to convert NSImage to NSBitmapImageRep? I have code: - (NSBitmapImageRep *)bitmapImageRepresentation { NSBitmapImageRep *ret = (NSBitmapImageRep *)[self representations]; if(![ret isKindOfClass:[NSBitmapImageRep class]]) { ret = nil; for(NSBitmapImageRep *rep in [self representations]) if([rep isKindOfClass:[NSBitmapImageRep class]]) { ret = rep; break; } } if(ret == nil) { NSSize size = [self size]; size_t width = size.width; size_t height = size.height; size_t bitsPerComp = 32; size_t

Resize CGImageRef without anti-liasing

半腔热情 提交于 2019-12-03 16:41:59
I am trying to resize a 10x10 pixel CGImageRef, captured like this: CGImageRef imageRef = CGImageCreateWithImageInRect(screenShot, CGRectMake(mouseLoc.x-5, screen_height-mouseLoc.y-5, 10, 10)); CGContextRef mainViewContentContext = CGBitmapContextCreate (NULL, maskImage.size.width, maskImage.size.height, 8, maskImage.size.height*4, colorSpace, kCGImageAlphaPremultipliedFirst); CGContextDrawImage(mainViewContentContext, NSMakeRect(0,0, maskImage.size.width, maskImage.size.height), imageRef); Then I need to make a 250x250 pixel image like this this , but the upscaled image looks like there is

Trying to resize an NSImage which turns into NSData

北城余情 提交于 2019-12-03 16:16:51
I have an NSImage which I am trying to resize like so; NSImage *capturePreviewFill = [[NSImage alloc] initWithData:previewData]; NSSize newSize; newSize.height = 160; newSize.width = 120; [capturePreviewFill setScalesWhenResized:YES]; [capturePreviewFill setSize:newSize]; NSData *resizedPreviewData = [capturePreviewFill TIFFRepresentation]; resizedCaptureImageBitmapRep = [[NSBitmapImageRep alloc] initWithData:resizedPreviewData]; saveData = [resizedCaptureImageBitmapRep representationUsingType:NSJPEGFileType properties:nil]; [saveData writeToFile:@"/Users/ricky/Desktop/Photo.jpg" atomically