Tôi đã tạo NSImage 32 bit với mã sau.Cách tạo biểu diễn 8-, 4 và 1 bit của NSImage
NSBitmapImageRep *sourceRep = [[NSBitmapImageRep alloc] initWithData: imageData];
// create a new bitmap representation scaled down
NSBitmapImageRep *newRep =
[[NSBitmapImageRep alloc]
initWithBitmapDataPlanes: NULL
pixelsWide: imageSize
pixelsHigh: imageSize
bitsPerSample: 8
samplesPerPixel: 4
hasAlpha: YES
isPlanar: NO
colorSpaceName: NSCalibratedRGBColorSpace
bytesPerRow: 0
bitsPerPixel: 0];
// save the graphics context, create a bitmap context and set it as current
[NSGraphicsContext saveGraphicsState] ;
NSGraphicsContext *context = [NSGraphicsContext graphicsContextWithBitmapImageRep: newRep];
[NSGraphicsContext setCurrentContext: context] ;
// draw the bitmap image representation in it and restore the context
[sourceRep drawInRect: NSMakeRect(0.0f, 0.0f, imageSize, imageSize)] ;
[NSGraphicsContext restoreGraphicsState] ;
// set the size of the new bitmap representation
[newRep setSize: NSMakeSize(imageSize,imageSize)] ;
NSDictionary *imageProps2 = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithFloat:1.0], kCGImageDestinationLossyCompressionQuality,
nil];
imageData = [newRep representationUsingType: NSPNGFileType properties: imageProps2];
NSImage *bitImage = [[NSImage alloc]initWithData:imageData];
Bây giờ tôi cần phải tạo ra 8 bit (256 màu), 4 bit (16 màu), 1 bit (Black & trắng) NSBitmapImageRep
đại diện. tôi muốn làm gì bây giờ?
Bạn có coi bộ lọc Hình ảnh lõi không? – uchuugaka
@ peterhosey, bất kỳ hạn chế nào về giấy phép hoặc thời gian xem xét thời gian chạy? như phải có sẵn như được xây dựng trong lib trong 10.6 vv? –
@GradyPlayer: Tôi không có bất kỳ hạn chế nào như vậy, không. (Tôi chỉ là những câu hỏi bountying cho những ngày nghỉ, tôi không cần điều này cho công việc hoặc một cái gì đó.) –