好的情况听起来很简单,但是我不知道该怎么做:

        //
        CGImageRef ImagRef      = [self imageFromSampleBuffer:sampleBuffer];

        // Allocate m_pIMAGE at the first frame
        if(m_pIMAGE == NULL)
        {
            m_pIMAGE = [[UIImage alloc] initWithCGImage:(ImagRef)];
        }
        else
        {
            // Copy the frame image (ImagRef) into the m_pIMAGE

        }


        CGImageRelease( ImagRef );

在第一帧分配了m_pIMAGE后,如何使用ImageRef更新它?

最佳答案

图片应在主线程中分配...

CGImageRef ImagRef = CGBitmapContextCreateImage(context);


CFRetain(ImagRef);
// Create an image object from the Quartz image
if([NSThread isMainThread]) {
    if(m_pIMAGE == NULL) {
        m_pIMAGE = [[UIImage alloc] initWithCGImage:(ImagRef)];
    } else {
    }
    CFRelease(ImagRef);
} else {
    dispatch_async(dispatch_get_main_queue(), ^{
        if(m_pIMAGE == NULL) {
            m_pIMAGE = [[UIImage alloc] initWithCGImage:(ImagRef)];
        } else {
        }
        CFRelease(ImagRef);
    });
}
// Release the Quartz image
CGImageRelease(ImagRef);

10-02 06:33