【问题标题】:QImage from datastream来自数据流的 QImage
【发布时间】:2010-02-23 10:46:31
【问题描述】:

我正在使用 Qt 库,创建 QImages。

我可以使用this constructor:

QImage image("example.jpg");

但我遇到了this static function 的问题:

char buffer[sizeOfFile];
ifstream inFile("example.jpg");
inFile.read(buffer, sizeOfFile);
QImage image = QImage::fromData(buffer); // error here
// but there's nothing wrong with the buffer
ofstream outFile("bufferOut.jpg");
outFile.write(buffer, sizeOfFile);

Qt 向控制台输出的地方:

Corrupt JPEG data: 1 extraneous bytes before marker 0xd9
JPEG datastream contains no image

以上内容并不是我所拥有的完全,但这是唯一重要的区别。 (我需要能够从缓冲区读取,因为我正在打开 zip 存档中的图像。)

【问题讨论】:

    标签: c++ qt qt4 qimage


    【解决方案1】:

    从 irc.freenode.net 上的#qt 到 peppe 的 Tnx:

    解决方案是显式包含缓冲区长度。忽略一些unsigned charchar 类型转换和其他细节,我应该使用类似于:

    QImage image = QImage::fromData(buffer, sizeOfFile);
    

    【讨论】:

    • 你和佩佩是帅哥!
    猜你喜欢
    • 1970-01-01
    • 2018-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-21
    • 2021-01-30
    • 1970-01-01
    相关资源
    最近更新 更多