How can i get informtion from an CGImageRef image?

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

  1. bker macrumors newbie

    Joined:
    May 22, 2010
    #1
    Hi,

    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!

    PHP:
        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
                                  pixelsWide
    : ?
                                  
    pixelsHigh: ?
                               
    bitsPerSample: ?
                             
    samplesPerPixel: ?
                                    
    hasAlpha: ?
                                    
    isPlanar: ?
                              
    colorSpaceName: ?
                                
    bitmapFormat: ?
                                 
    bytesPerRow: ?
                                
    bitsPerPixel: ?
         ];
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    http://developer.apple.com/mac/libr...//apple_ref/doc/uid/TP30000956-CH1g-TPXREF183

    But you should instead use -[NSBitmapImageRep initWithCGImage:]

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

    Code:
    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