发送UIImage作为字节? [英] send UIImage as bytes?
问题描述
我有一个UIImageView,其中包含用手机的摄像头拍摄的图像.
I have a UIImageView which contains a image taken with the camera of the phone.
我接下来要做的就是将此图像发送到服务器.我已经使用CFstream设置了套接字连接.
Next thing that i want to do is send this image to a server. I already have the socket connections set up using the CFstreams.
但是我真的无法使它正常工作.我有一个UIImage对象,我想通过TCP连接以某种方式发送该对象...
But i really can't get this to work. I have a UIImage object, which i want to send over somehow with my TCP connection...
我试图像这样发送NSData,但它给了我一个错误:代码:
I tried to send a NSData like so, but it gives me an error: Code:
// Getting image from OpenCV and converting it back to UIImage
NSData *data = UIImagePNGRepresentation([UIImage imageWithCVMat:tpl]);
uint32_t length = (uint32_t)htonl([data length]);
// Send the image? (Doesn't work)
[outputStream write:[data bytes] maxLength:length];
错误:语义问题:无法初始化类型为'const的参数uint8_t *'(又名'const unsigned char *'),其右值为'const无效*'
error: Semantic Issue: Cannot initialize a parameter of type 'const uint8_t *' (aka 'const unsigned char *') with an rvalue of type 'const void *'
所以任何人都想知道如何通过outputStream writer将UIImage(View)中的图像作为字节数组发送吗?
So anyone any idea how to send an image from a UIImage(View) as a byte array through the outputStream writer??
推荐答案
在这种情况下,您可以放心地投射:
In this case you can safely cast:
[outputStream write:(const uint8_t *)[data bytes] maxLength:length];
因为您知道(void *)数据的来源.
since you know where the (void*) data comes from.
这篇关于发送UIImage作为字节?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!