NSImage turn out black

Discussion in 'Mac Programming' started by larswik, Aug 29, 2015.

  1. larswik macrumors 68000

    Sep 8, 2006
    My program is almost finished and runs great in 10.10 but creates black frames in 10.7.

    After testing back and forth I found the problem area but I can't find out why it is doing causing this problem. My app does this... Originally the app took 4 grocery store product photos and combined them to 1 large TIF image with prices and information that was 5120 x720. I take this image in to Adobe After Effects to create a video animation of the images sliding to the side and create an mp4 video for the stores to playback weekly.

    Now my app creates the animating images and generates an mp4 video file with the press of a button saving me the steps of using after effects. Only problem is it only creates black frames on 10.7. I discovered the problem is a method I use to apply a vignette to the image and then return the image. When I bypass this method it works in 10.7

    The createFrame method is called 540 times, that creates the still images animation and stores them in an array to be used to make the mp4 video. This method works fine. At the bottom of this method I send the NSImage to a different method, convertToCIImage: to apply the vignette. When I bypass the convertToCIImage: method and write the NSImage to the array it works fine under 10.7. But applying the filter in the convertToCIImage: I get nothing but black frames returned? Everything looks to be 10.7 compliant and works perfectly in 10.10, but not 10.7? Any ideas why it's just generating black frames in 10.7?

        NSImage *toSaveImage = [[NSImage alloc] initWithSize:CGSizeMake(1280, 720)]; // image to save after created.
        NSImage *backDropImage = [NSImage imageNamed:@"wood_comp"];
        NSImage *blackImage = [self returnColorLayer]; // apply with and alpha of 0.5 to darken the layer behind
        NSShadow *shadow = [[NSShadow alloc]init];
        shadow.shadowOffset = CGSizeMake(15.0, -15.0);
        shadow.shadowBlurRadius = 7.0;
        [shadow setShadowColor:[NSColor colorWithCalibratedWhite:0.0 alpha:0.5]];
        [toSaveImage lockFocus]; //prep for writing to image
        [backDropImage drawInRect:NSMakeRect(bgIntArray[indexPos], 0, 6000, 720) fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];
        [blackImage drawInRect:NSMakeRect(0, 0, 6000, 720)  fromRect:NSZeroRect  operation:NSCompositeSourceOver fraction:0.4]; // black color
        [shadow set];
        [importImage drawInRect:NSMakeRect(pIntArray[indexPos], 0, 1280 * 4, 720) fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];
        [dateInfomation drawInRect:drawRectString withAttributes:textAttributesDict];
        [toSaveImage unlockFocus];
        //[framesArray addObject:[self convertToCIImage:toSaveImage]];
        [framesArray addObject:toSaveImage];
        frameNumber++; // starts with 1
        NSData  * iData = [image TIFFRepresentationUsingCompression: NSTIFFCompressionNone factor: 0.0f];
        CIImage *cim = [CIImage imageWithData:iData]; // use NSData to convert to a CIImage
        CIFilter *vinette = [CIFilter filterWithName:@"CIVignette"];
        [vinette setValue:cim forKey:kCIInputImageKey];
        [vinette setValue:@1.0 forKey:@"inputIntensity"];
        [vinette setValue:@1.5 forKey:@"inputRadius"];
        CIImage *filterImage = [vinette valueForKey:@"outputImage"];
        NSCIImageRep *rep = [NSCIImageRep imageRepWithCIImage:filterImage];
        NSImage *nsImage = [[NSImage alloc] initWithSize:rep.size];
        [nsImage addRepresentation:rep];
        return nsImage;
  2. xStep macrumors 68000

    Jan 28, 2003
    Less lost in L.A.
    The docs say:

    Available in OS X v10.9 and later and in iOS 5.0 and later."
  3. larswik thread starter macrumors 68000

    Sep 8, 2006
    I see it now... I was checking the Methods and Classes with the quick help inspector. It tells you the availability. I did't know I needed to check strings / filter names like @"CIVignette". did;t know they also had an availability in OS. You are correct, it says 10.9 for CIVignette.

    Thank you.

Share This Page