如何使用 Qt 从缓冲区加载图像?

发布于 2024-12-05 16:12:06 字数 179 浏览 5 评论 0 原文

因此输入:

QBuffer* buffer = new QBuffer(this->Conex);
QImage* image = new QImage ();
image->loadFromData (buffer->buffer());

这对我不起作用。

Thus type:

QBuffer* buffer = new QBuffer(this->Conex);
QImage* image = new QImage ();
image->loadFromData (buffer->buffer());

This does not work for me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

匿名的好友 2024-12-12 16:12:06

如果缓冲区包含原始像素数据,您可能需要使用此构造函数指定宽度、高度和 bpp:

QImage::QImage ( uchar * data, int width, int height, int bytesPerLine, Format format )

编辑:

这就是您使用此构造函数的方式:

int imageWidth = 800;
int imageHeight = 600;
int bytesPerPixel = 4; // 4 for RGBA, 3 for RGB
int format = QImage::Format_ARGB32; // this is the pixel format - check Qimage::Format enum type for more options
QImage image(yourData, imageWidth, imageHeight, imageWidth * bytesPerPixel, format);

If the buffer contains raw pixel data, you might want to specify the width, height and bpp using this constructor:

QImage::QImage ( uchar * data, int width, int height, int bytesPerLine, Format format )

Edit:

That's how you would use this constructor:

int imageWidth = 800;
int imageHeight = 600;
int bytesPerPixel = 4; // 4 for RGBA, 3 for RGB
int format = QImage::Format_ARGB32; // this is the pixel format - check Qimage::Format enum type for more options
QImage image(yourData, imageWidth, imageHeight, imageWidth * bytesPerPixel, format);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文