来自数据流的 QImage
我正在使用 Qt 库创建 QImage。
我可以使用这个构造函数:
QImage image("example.jpg");
但是我有这个静态函数有问题:
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 存档内的图像。)
I'm using the Qt library, creating QImages.
I'm able to use this constructor:
QImage image("example.jpg");
But I'm having trouble with 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);
Where Qt spits out to console:
Corrupt JPEG data: 1 extraneous bytes before marker 0xd9
JPEG datastream contains no image
The above isn't exactly what I have, but it's the only important difference. (I need to be able to read from a buffer because I'm opening images that are inside a zip archive.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Tnx to peppe from #qt on irc.freenode.net:
解决方案是显式包含缓冲区长度。忽略一些
unsigned char
到char
类型转换和其他细节,我应该使用类似于:Tnx to peppe from #qt on irc.freenode.net:
The solution is to explicitly include the buffer length. Ignoring a few
unsigned char
tochar
typecasting and other details, what I should have used is something akin to: