Tôi đang gặp một số sự cố khi tải UIIMage từ CVPixelBuffer. Đây là những gì tôi đang cố gắng:Làm cách nào để biến CVPixelBuffer thành UIImage?
CVPixelBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(imageDataSampleBuffer);
CFDictionaryRef attachments = CMCopyDictionaryOfAttachments(kCFAllocatorDefault, imageDataSampleBuffer, kCMAttachmentMode_ShouldPropagate);
CIImage *ciImage = [[CIImage alloc] initWithCVPixelBuffer:pixelBuffer options:(NSDictionary *)attachments];
if (attachments)
CFRelease(attachments);
size_t width = CVPixelBufferGetWidth(pixelBuffer);
size_t height = CVPixelBufferGetHeight(pixelBuffer);
if (width && height) { // test to make sure we have valid dimensions
UIImage *image = [[UIImage alloc] initWithCIImage:ciImage];
UIImageView *lv = [[UIImageView alloc] initWithFrame:self.view.frame];
lv.contentMode = UIViewContentModeScaleAspectFill;
self.lockedView = lv;
[lv release];
self.lockedView.image = image;
[image release];
}
[ciImage release];
height
và width
đều thiết lập đúng với độ phân giải của máy ảnh. image
được tạo nhưng tôi có vẻ là màu đen (hoặc có thể trong suốt?). Tôi hoàn toàn không thể hiểu được vấn đề ở đâu. Có những câu chuyện mới trên trang chủ.
Bạn chắc chắn muốn có một CIImage ở giữa, ví dụ: bởi vì bạn sẽ ném một số CIFilters trung gian vào, hoặc nó sẽ được chấp nhận chỉ để đi CGBitmapContextCreate -> UIImage? – Tommy
Bây giờ, tôi chỉ muốn hiển thị nó trong một cái nhìn và xem những gì tôi đang xử lý. Xuống đường, tôi muốn chơi với các điểm ảnh. – mahboudz