nsbitmapimagerep

cocoa: Read pixel color of NSImage

那年仲夏 提交于 2020-01-01 11:49:17
问题 I have an NSImage . I would like to read the NSColor for a pixel at some x and y. Xcode seems to thing that there is a colorAtX:y: method on NSImage , but this causes a crash saying that there is no such method for NSImage. I have seen some examples where you create an NSBitmapImageRep and call the same method on that, but I have not been able to successfully convert my NSImage to an NSBitmapImageRep . The pixels on the NSBitmapImageRep are different for some reason. There must be a simple

Is it possible to make a NSBitmapImageRep with 24 bpp and no alpha channel?

浪子不回头ぞ 提交于 2019-12-18 07:02:46
问题 I don't understand really well the premultiplied alpha. I need a NSBitmapImageRep without alpha channel (I don't need a particular bpp). My problem is that this code give me errors: NSSize imageSize = NSMakeSize(200, 200); //create a non-alpha RGB image rep with the same dimensions as the image NSBitmapImageRep* bitmap = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL pixelsWide:imageSize.width pixelsHigh:imageSize.height bitsPerSample:8 samplesPerPixel:3 hasAlpha:NO isPlanar:NO

Using CALayer's renderInContext: method with geometryFlipped

烂漫一生 提交于 2019-12-18 04:50:35
问题 I have a CALayer ( containerLayer ) that I'm looking to convert to a NSBitmapImageRep before saving the data out as a flat file. containerLayer has its geometryFlipped property set to YES, and this seems to be causing issues. The PNG file that is ultimately generated renders the content correctly, but doesn't seem to takes the flipped geometry into account. I'm obviously looking for test.png to accurately represent the content shown to the left. Attached below is a screenshot of the problem

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

NSImage to NSBitmapImageRep

跟風遠走 提交于 2019-12-03 06:21:48
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 bytesPerPixel = (bitsPerComp / CHAR_BIT) * 4; size_t bytesPerRow = bytesPerPixel * width; size_t

Is it possible to make a NSBitmapImageRep with 24 bpp and no alpha channel?

独自空忆成欢 提交于 2019-11-29 11:41:02
I don't understand really well the premultiplied alpha. I need a NSBitmapImageRep without alpha channel (I don't need a particular bpp). My problem is that this code give me errors: NSSize imageSize = NSMakeSize(200, 200); //create a non-alpha RGB image rep with the same dimensions as the image NSBitmapImageRep* bitmap = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL pixelsWide:imageSize.width pixelsHigh:imageSize.height bitsPerSample:8 samplesPerPixel:3 hasAlpha:NO isPlanar:NO bitmapFormat:NSAlphaNonpremultipliedBitmapFormat bytesPerRow:(3 * imageSize.width) bitsPerPixel:24]; //lock

Using CALayer's renderInContext: method with geometryFlipped

旧城冷巷雨未停 提交于 2019-11-29 06:59:08
I have a CALayer ( containerLayer ) that I'm looking to convert to a NSBitmapImageRep before saving the data out as a flat file. containerLayer has its geometryFlipped property set to YES, and this seems to be causing issues. The PNG file that is ultimately generated renders the content correctly, but doesn't seem to takes the flipped geometry into account. I'm obviously looking for test.png to accurately represent the content shown to the left. Attached below is a screenshot of the problem and the code I'm working with. - (NSBitmapImageRep *)exportToImageRep { CGContextRef context = NULL;

How to save PNG file from NSImage (retina issues)

戏子无情 提交于 2019-11-27 00:45:56
I'm doing some operations on images and after I'm done, I want to save the image as PNG on disk. I'm doing the following: + (void)saveImage:(NSImage *)image atPath:(NSString *)path { [image lockFocus] ; NSBitmapImageRep *imageRepresentation = [[NSBitmapImageRep alloc] initWithFocusedViewRect:NSMakeRect(0.0, 0.0, image.size.width, image.size.height)] ; [image unlockFocus] ; NSData *data = [imageRepresentation representationUsingType:NSPNGFileType properties:nil]; [data writeToFile:path atomically:YES]; } This code is working, but the problem is with retina mac, if I print the NSBitmapImageRep

How to save PNG file from NSImage (retina issues)

江枫思渺然 提交于 2019-11-26 09:26:07
问题 I\'m doing some operations on images and after I\'m done, I want to save the image as PNG on disk. I\'m doing the following: + (void)saveImage:(NSImage *)image atPath:(NSString *)path { [image lockFocus] ; NSBitmapImageRep *imageRepresentation = [[NSBitmapImageRep alloc] initWithFocusedViewRect:NSMakeRect(0.0, 0.0, image.size.width, image.size.height)] ; [image unlockFocus] ; NSData *data = [imageRepresentation representationUsingType:NSPNGFileType properties:nil]; [data writeToFile:path