【发布时间】:2014-11-06 14:12:33
【问题描述】:
我们如何在 iOS 7 中使用蓝牙或 wifi 有效地将相机源从一台 iOS 设备传输到另一台设备。下面是获取流缓冲区的代码。
- (void)captureOutput:(AVCaptureOutput *)captureOutput
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
fromConnection:(AVCaptureConnection *)connection
{
// Create a UIImage from the sample buffer data
UIImage *image = [self imageFromSampleBuffer:sampleBuffer];
}
// Create a UIImage from sample buffer data
- (UIImage *) imageFromSampleBuffer:(CMSampleBufferRef) sampleBuffer
{
// Get a CMSampleBuffer's Core Video image buffer for the media data
CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
// Lock the base address of the pixel buffer
CVPixelBufferLockBaseAddress(imageBuffer, 0);
// Get the number of bytes per row for the pixel buffer
void *baseAddress = CVPixelBufferGetBaseAddress(imageBuffer);
// Get the number of bytes per row for the pixel buffer
size_t bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer);
// Get the pixel buffer width and height
size_t width = CVPixelBufferGetWidth(imageBuffer);
size_t height = CVPixelBufferGetHeight(imageBuffer);
// Create a device-dependent RGB color space
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
// Create a bitmap graphics context with the sample buffer data
CGContextRef context = CGBitmapContextCreate(baseAddress, width, height, 8,
bytesPerRow, colorSpace, kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst);
// Create a Quartz image from the pixel data in the bitmap graphics context
CGImageRef quartzImage = CGBitmapContextCreateImage(context);
// Unlock the pixel buffer
CVPixelBufferUnlockBaseAddress(imageBuffer,0);
// Free up the context and color space
CGContextRelease(context);
CGColorSpaceRelease(colorSpace);
// Create an image object from the Quartz image
UIImage *image = [UIImage imageWithCGImage:quartzImage];
// Release the Quartz image
CGImageRelease(quartzImage);
return (image);
}
在这里我们可以得到 iOS 相机正在捕获的图像。
我们可以使用多对等点将样本缓冲区信息直接发送到另一台设备,还是有任何有效的方法将数据传送到其他 iOS 设备?
谢谢。
【问题讨论】:
-
Multipeer Connectivity 听起来像是一个有效的选项。但是你需要检查性能。发送未压缩的图像可能需要太多带宽,因此您可能必须创建一个真实的视频流才能传输实时捕获。
-
编辑必须是 6 个字符,所以除非我们想出填充符,否则这篇文章将永远成为 feed
-
好问题 Sandipbhai,赞成..
标签: ios bluetooth core-bluetooth avcapturesession multipeer-connectivity