- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在开发 C++ QT 项目,该项目包含一些模块,这些模块使用带有签名的函数通过一个 Controller 模块相互通信:
notify(QString stream_id, const void* stream, unsigned __int64 size)
所以我问的是如何将 QT 数据类型主要是 QImage* 转换为 void*,反之亦然,以使用 void 指针及其大小发送数据,
我正在尝试使用这段代码,但它不起作用:
void* imageVoidPtr = static_cast<void*>(&image);
StreamListener::getInstance()->notify(QString("Stream_Name"),imageVoidPtr,sizeof(imageVoidPtr));
------------ 编辑
我正在尝试使用以下方法检索数据:
void VideoView::receive(QString stream_id, const void* stream, unsigned __int64 size){
QByteArray data = QByteArray::fromRawData(reinterpret_cast<const char*>(stream), size);
QBuffer buffer(&data);
QImageReader reader(&buffer);
QImage img = reader.read();}
-------- 编辑 2
Void* 缓冲区的大小为 4 或 12(在 sizeOf(QImage) 的情况下)并且没有给出正确的图像字节大小的代码有什么问题,并且接收器中接收到的图像是空的(没有出现错误)。
谢谢
最佳答案
令人惊奇的是,您期望它能起作用。
指针只是一个整数,表示可以保存任意数据的内存地址。因此,无论指针指向什么,指针的大小始终相同,因为它始终是内存地址,并且始终由固定位数表示,32 位版本中为 32 位,64 位版本中为 64 位。
QImage
将数据存储在堆上。实际类只是数据的 Controller 。因此,无论图像有多大,sizeof()
都会给您相同的结果。
QImage
已经支持使用 QDataStream
进行序列化和反序列化:
QImage img(100, 100, QImage::Format_Mono); // original image
QByteArray data; // data container
QBuffer buffer(&data); // io device
buffer.open(QIODevice::ReadWrite);
QDataStream stream(&buffer); // data stream
stream << img; // save img to data
// you can now use the data.data() pointer, convert to void, and send data.size() number of bytes and put it into another byte array on the other side
// then replicate the io dev and data stream steps too, omitted for brevity
QImage img2; // new image
buffer.seek(0); // go to beginning of data
stream >> img2; // read data into new image
qDebug() << (img == img2) << data.size(); // true, it is the same content, size is 723 bytes, that includes the image format and raw data
关于c++ - 将 QImage* 转换为 void* ,反之亦然,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48862884/
我正在寻找一种方法来简单地将一些Qimage粘贴到更大的图像中,从一些给定的(x,y)开始。现在,我正在逐像素复制所有Qimage。 最佳答案 QImage srcImage = QImage(100
我正在开发一个图像处理程序,当程序不断收到这些消息时,这里有一些示例,但我收到了数百条消息,以至于程序无法完全执行。 QImage::setPixel: coordinate (1043968,0)
我尝试将具有 RGB32 的 QImage 转换为具有 RGB24 的 QImage。我的代码在这种情况下不起作用: 当图片在BMP头中多出1024字节时,图片的大小为X*Y*3+54+未知的1024
我找到了类似的主题,但不是这个特定的主题。知道以下代码有什么问题吗?它返回'loaded=false',这显然意味着无法加载图像数据。 cv::Mat mymat; QImage qimg; myma
我创建了一个 Publisher 类,它定期发出 QImage 对象。 但是,我很难将 QImage 绘制到 QML 元素。 Image 和 Canvas QML 组件似乎需要 QUrl 而不是 QI
我是图形编程的新手(像素、图像等) 我正在尝试将原始数据转换为 QImage 并将其显示在 QLabel 上。问题是,原始数据可以是任何数据(它实际上不是图像原始数据,而是二进制文件。) 原因是,为了
是 QImage基于 QSharedData ?做 Qimage关注 pimpl或 copy on write ? 例如复制(通过复制骗局或分配)Qimage 会复制像素的深拷贝吗? 最佳答案 QIm
我正在调试一个巨大的 Qt 应用程序,其中包含数百个类、凌乱的代码等。在跟踪错误的同时,我想单步执行 gdb(kdbg、ddd 等等),同时观察使用 QPainter 绘制到 QImage 中的内容这
如何清除或清理 QIMage 我的以下方法获取对 QIMage 的常量引用。 MyMethod(const QImage & img) { // save it to a file img.s
我正在尝试将Format_Grayscale8图像转换为Format_ARGB32(或任何其他8bpp RGB格式)。我尝试使用QImage::convertToFormat和颜色表,但无法正常工作。
我正在使用 Qt 库创建 QImages。 我可以使用 this constructor : QImage image("example.jpg"); 但是我遇到了 this static funct
我知道 QImage 的高度和宽度,以及每个像素值(从 x、y 位置)。我如何构建一个知道这些值的 QImage? 最佳答案 setPixel() 的第二个参数是单个 int 中的 24 位 RGB
我正在开发用于编辑光栅图形的应用程序。在这个应用程序中,我必须创建扫描线函数,它与 QImage 类中的扫描线函数做同样的事情。但是我对扫描线函数的工作方式和一般的扫描线有点困惑。例如,当我为高度为
我的工作基于 this answer ,我正在尝试使用 Qt 的 QGLWidget 来呈现视频,但我遇到了一些问题。在我的视频解码线程中解码后立即保存帧时,结果很好: 但是当画出来的时候,它被严重破
我目前使用的是 Qt 5.12.3,在理解 QImage::pixel 函数的 10 位数字输出时遇到问题。对于此代码: QImage image; image.load("D:/qtProjects
我有一个简单的绘图应用程序,但是当我调整窗口大小时图像被删除,我想保留它。我尝试使用 image.scaled(current size) 但它不起作用。 qDebug() size(); QImag
我正在尝试显示 QImage在 QML 中,可能带有 Image .目前,我发现了类似 QQuickImageProvider 的内容,我实现并尝试使用,但没有成功。 我有QList我自己的对象( I
QImage具有以下构造函数: QImage(const QString &fileName, const char *format = nullptr); 但是,我正在尝试解析已作为字节数组加载的
我在我的 qt quick 应用程序中用相机捕获了一个图像。我想将路径发送到我的 c++ 代码并在 c++ QImage 中加载该图像。但是路径是 image://camera/preview_1 我
在我控制窗口的主类中,我有这个函数,其中 pixmapItem 是类头中定义的 QGraphicsPixmapItem*: void updateDisplay() { uchar *data
我是一名优秀的程序员,十分优秀!