我正在開發一個可以觀看網絡攝像頭視頻的應用程序。現在我想通過使用後臺線程添加一個新的記錄視頻功能。獲取[不是類型保留]和[不是類型類別]消息發送到已釋放的實例
在.m文件.h文件中
@property (nonatomic, retain) UIImage *image;
@property (nonatomic, retain) NSData *imageData;
。當用戶按下錄製按鈕時,它開始將ImageData保存到文檔目錄
@synthesize image;
@synthesize imageData
...
- (void) playVideo:(NSData *)data {
...
// play video code
CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault;
CGDataProviderRef provider = CGDataProviderCreateWithCFData(data);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGImageRef cgImage = CGImageCreate(width, hieght, 8, 24,
bpp * width, colorSpace, bitmapInfo,
provider, NULL, NO, kCGRenderingIntentDefault);
CGColorSpaceRelease(colorSpace);
[videoImage = [setImage: UIImage imageWithCGImage:cgImage]];
CGImageRelease(cgImage);
CGDataProviderRelease(provider);
// play video code end
...
if(record == TRUE) {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,
(unsigned long)NULL), ^(void) {
image = [UIImage imageWithCGimage:cgImage];
imageData = [UIImageJPEGRepresentation(image, 1)];
[imageData writeToFile:DirPath atomically:NO];
});
}
}
播放視頻代碼似乎目前工作正常。然後我在它下面添加線程,並在線程中收到錯誤消息
[Not a type retain]: message sent to deallocated instance
[Not a type class]: message sent to deallocated instance
image = [UIImage imageWithCGimage:cgImage];
你能告訴我爲什麼會這樣嗎?或者有其他方式來做到這一點。謝謝。
'cgImage'從哪裏來? – jere