1

好的,这个案例听起来很简单,但我不知道该怎么做:

        //
        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 );

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

4

2 回答 2

2

使用 ARC,只需重新初始化它,否则。释放并将指针设置为 nil。然后重新分配

于 2013-05-28T11:41:13.920 回答
2

图像应该在主线程中分配......

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);
于 2013-05-28T11:48:22.373 回答