2

I am using AVAssetWriterInputPixelBufferAdaptor to create a video from an array of UIImage's, and i want to change the transition from one image to another in different forms of animations(much like a slide show ... actually exactly like a slideshow).

One of these transitional styles is fade out. since im writing UIImages like so ..

    UIImage *image = imageView.image;
    UIImage *resizedImage = [ICVideoViewController imageWithImage:image scaledToSize:CGSizeMake(640, 480)];
    CGImageRef img = [resizedImage CGImage];
    CVPixelBufferRef buffer = [ICVideoViewController pixelBufferFromCGImage:img size:CGSizeMake(640, 480)];

    [adaptor appendPixelBuffer:buffer withPresentationTime:CMTimeMake(i, 1)];

I would like to know if it is possible (without having to manually manipulate the pixels) to achieve this .. ?

Aatish Molasi
  • 1,938
  • 3
  • 17
  • 42

2 Answers2

2

I dont know how you are creating image in imagawithimage function of your view controller.

If you are using CGContext to scale image then use CGContextSetAlpha() before CGContextDrawImage().

If not you can do one more thing, no doubt you will need to code few more lines for that but this can be one way :

CGSize size = [self size];
int width = size.width;
int height = size.height;

// the pixels will be painted to this array
uint32_t *pixels = (uint32_t *) malloc(width * height * sizeof(uint32_t));

// clear the pixels so any transparency is preserved
memset(pixels, 0, width * height * sizeof(uint32_t));

CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();

// create a context with RGBA pixels
CGContextRef context = CGBitmapContextCreate(pixels, width, height, 8, width * sizeof(uint32_t), colorSpace, 
                                             kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedLast);

// paint the bitmap to our context which will fill in the pixels array
CGContextSetAlpha(context, 0.5);
CGContextDrawImage(context, CGRectMake(0, 0, width, height), [self CGImage]);
CGImageRef image = CGBitmapContextCreateImage(context);

CGContextRelease(context);
CGColorSpaceRelease(colorSpace);
free(pixels);
DivineDesert
  • 6,858
  • 1
  • 26
  • 61
2

How about blending the two images you're transitioning?

See the following thread: blend two uiimages based on alpha/transparency of top image

Community
  • 1
  • 1
serb
  • 298
  • 3
  • 11