How can i get informtion from an CGImageRef image?

Discussion in 'Mac Programming' started by bker, Jun 6, 2010.

  1. bker macrumors newbie

    May 22, 2010

    I would like to know how can i get information from a CGImageRef image to put them into initWithBitmapDataPlanes like bitsPerSample, hasAlpha, bitsPerPixel etc... ?
    Thank you!

        NSImage *imagePath = [[NSImage allocinitWithContentsOfFile:@"/Users/bker/Desktop/TEST/001.jpg"];
    //NSImage *imagePath = [[NSImage alloc] initWithContentsOfFile:@"/Users/bker/Desktop/TEST/001.png"];
        //NSImage *imagePath = [[NSImage alloc] initWithContentsOfFile:@"/Users/bker/Desktop/TEST/001.tiff"];

    CGImageSourceRef asource CGImageSourceCreateWithData((CFDataRef)[imagePath TIFFRepresentation], NULL);
    CGImageRef bitmap =  CGImageSourceCreateImageAtIndex(asource0NULL);
    NSBitmapImageRep *bitmap = [NSBitmapImageRep alloc];
    bitmap initWithBitmapDataPlanes:NULL
    : ?
    pixelsHigh: ?
    bitsPerSample: ?
    samplesPerPixel: ?
    hasAlpha: ?
    isPlanar: ?
    colorSpaceName: ?
    bitmapFormat: ?
    bytesPerRow: ?
    bitsPerPixel: ?
  2. kainjow Moderator emeritus


    Jun 15, 2000

    But you should instead use -[NSBitmapImageRep initWithCGImage:]

    Also your initialization is wrong. You should use this format:

    NSBitmapImageRep *bitmap = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes...
    EDIT: instead of loading an NSImage, getting its TIFF, loading that TIFF into a CGImageSource, then loading that CGImage into an NSBitmapImageRep, just create the CGImageSource via CGImageSourceCreateWithURL() with the file URL, then use initWithCGImage: to create your NSBitmapImageRep.

Share This Page