changing color depth of image data

Discussion in 'Mac Programming' started by ruhi, Dec 11, 2009.

  1. ruhi macrumors member

    Jun 17, 2009

    I have a CGImageRef which i have created by:

    CGImageRef screenShot = CGWindowListCreateImage(bound , kCGWindowListOptionOnScreenOnly, kCGNullWindowID, kCGWindowImageDefault );

    This CGImageRef is now used to create NSBitmapImageRep:

    NSBitmapImageRep *bitmapRep = [[NSBitmapImageRep alloc] initWithCGImage:cgImage];

    data=[bitmapRep representationUsingType:NSJPEGFileType properties:[NSDictionary dictionaryWithObject:NSImageCompressionMethod forKey:mad:"compression"]];

    Now i have the image data with me, i want change the color depth per pixel to 256 colors or 32 bit, How can i do that?

  2. kainjow Moderator emeritus


    Jun 15, 2000
    You have the JPEG data, not the image data. Those are two different things.

    I believe what you might need to do is create a new NSBitmapImageRep with your specified settings (or use a CGBitmapContext) and then draw your existing image into that new bitmap. Then, you can get a JPEG representation to write it to file.

Share This Page