如何将(OS_dispatch_data *)5018112字节转换为NSData以放入UIImage [英] How to convert (OS_dispatch_data *) 5018112 bytes into NSData to put into UIImage
问题描述
我一直在寻找答案,有些似乎是我需要的,但我不确定.我发现了这个问题#9152851 和这个
I've been looking for an answer to this and some seem like they might be what I need but I'm not sure. I found this Question #9152851 and this Question #2617625 and poked around on a bunch of links but I need some direction here.
本质上,我正在调度一个异步调用以使用OpenCV处理图像.您可以通过此处的代码看到,在将其发送回我的委托人之前,我将其转换为NSData *.
Essentially, I'm dispatching an async call to process an image using OpenCV. You can see by the code here that I'm turning it into NSData * before sending it back to my delegate.
NSData *proccessedData = [NSData dataWithBytes:processedImage.data length:(processedImage.rows * processedImage.cols)];
[self.delegate onProcessedBitmapReady:proccessedData withFocusQuality:focusQuality];
但是当我返回到委托人时,我的processingBitmap的类型为(OS_dispatch_data *),并且包含字节值.因此,当我尝试设置UIImage时,它将设置为null.
But when I get back to my delegate, my processedBitmap is of type (OS_dispatch_data *) and contains a value of bytes. So, when I try to set the UIImage, it gets set to null.
- (void)onProcessedBitmapReady:(NSData *)processedBitmap withFocusQuality:(double)focusQuality
{
//Use comverted image from self.captureCommand onComplete
UIImage *image = [[UIImage alloc] initWithData:processedBitmap];
[self saveImage:image];
}
以下是这些值的屏幕截图:
Here is a screen capture of the values:
那么,如何将这些字节(或它们的任何字节)转换成可以填充到UIImage中的东西?
So, how do I convert those bytes (or whatever they are) into something that I can stuff into a UIImage?
预先感谢您的帮助.
--------------------------------------------------- -------- 添加新图像 ------------------------------- ----------
------------------------------------------------------- Adding a new image -----------------------------------------
这个新图片有帮助吗?
谢谢.
推荐答案
NSData
实际上是一个仅提供接口的类集群,并且周围有多种特殊实现.看来OS_dispatch_data
是这样一种特殊的实现,它可以在块周围传递数据对象,特别是因为您的UIImage
创建不会崩溃(就像传递非NSData
对象或只是垃圾内存一样) ).而是UIImage
根本无法识别图像的格式!
NSData
is actually a class cluster which just provides the interface, and there are multiple special implementations for it around. It appears that OS_dispatch_data
is such a special implementations made to pass data objects around blocks, especially since your UIImage
creation doesn't crash (as it would if you would pass it a non NSData
object, or just garbage memory). Instead, it looks like UIImage
simply doesn't recognize the format the image is in!
顺便说一句,Apple提供了有关类群集概念的出色指南,可以在
By the way, Apple has a great guide about the concept of class clusters, which can be found here.
这篇关于如何将(OS_dispatch_data *)5018112字节转换为NSData以放入UIImage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!