开发者

Add overlay / Manipulate using AVFoundation for iPhone?

开发者 https://www.devze.com 2023-03-06 12:39 出处:网络
I am new to the whole AVFoundation thing. Before I was using the good old UIImagePickerControllerSourceTypeCamera.

I am new to the whole AVFoundation thing. Before I was using the good old UIImagePickerControllerSourceTypeCamera.

I basically want to do a combination of adding a overlay of a semi-opaque overlay as well as manipulating the pixels to create a black & white effect, sepia, etc.

I a开发者_如何学Gom displaying it and capturing it using the AVFoundation framework and I can take a still frame it, but I don't know how to add a overlay.

Please help. Thanks.


If you are going to do any significant amount of processing on the image then I suggest you use OpenGL ES. If it is simple, such as an overlay, then you can use CoreGraphics.

Here is a quick snip it to get at the pixels.

void modifyImage(CMSampleBufferRef source) {
    CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(source);
    CVPixelBufferLockBaseAddress(imageBuffer,0);

    size_t bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer);
    size_t width = CVPixelBufferGetWidth(imageBuffer);
    size_t height = CVPixelBufferGetHeight(imageBuffer);
    void *src_buff = CVPixelBufferGetBaseAddress(imageBuffer);

    int32_t *src = (int32_t*) src_buff;

    //modify the image

    CVPixelBufferUnlockBaseAddress(imageBuffer, 0);
    return;
}

For a good starting point using OpenGL ES to process video see Brad Larson's blog.

0

精彩评论

暂无评论...
验证码 换一张
取 消