Reputation: 2186
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 .. ?
Upvotes: 2
Views: 779
Reputation: 318
How about blending the two images you're transitioning?
See the following thread: blend two uiimages based on alpha/transparency of top image
Upvotes: 3
Reputation: 6954
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);
Upvotes: 2