Constructing QImage from QBytearray
Hi
I am reading a raw binary data from a file into QBytearray. I want to use the QBytearray to construct a QImage. My code is shown below.
Code:
fileIn.
open(QFile::ReadOnly);
BPlaneIN->setPixmap(qp);
Quote:
error: conversion from `QByteArray' to `const uchar*' is ambiguous
Could some tell me why I get this error message. I have used scanline to get this working but am confused as to why this method of loading the buffer doesnt
Regards
Re: Constructing QImage from QBytearray
try something like this
Code:
...
img = QImage::fromData(data,
"PNG");
//the second param is format name ...
Re: Constructing QImage from QBytearray
Thanks Spirit
But it isnt "PNG" format, it is raw 8bit data. The intention is to create an empty QImage, the load QByteArray with data from a file. Then use QImage::fromData to load the QImage buffer. I dont understand why I need to specify a file format?
It does stop the compiler warning. Why is that?
Regards
Re: Constructing QImage from QBytearray
Quote:
Originally Posted by
dbrmik
I dont understand why I need to specify a file format?
how do you think QImage recognize image format? from special field in data.
so, if you data have no specifiyed format then you need to fill QImage pixel by pixel. on this forum this is question was discussed many times use search by forum.
Re: Constructing QImage from QBytearray
Hi
But I am specifying the image format it is "Format_Indexed8"
Code:
//load pixel data
//empty image
//load pixel data into empty image from QByteArray
I just dont understand why the above does not work?
Regards
Re: Constructing QImage from QBytearray
read this reading and writting image files.
QImage::Format is not format of file, this is pixel format.
Re: Constructing QImage from QBytearray
Hi
Thanks, Yes I've read it. The data loaded from the file is raw 8bit binary data. I want to load the data into QByteArray and then load the image buffer with the contents of QByteArray.
Is this QImage member funxction
Quote:
bool QImage::loadFromData ( const QByteArray & data, const char * format = 0 )
equivalent to
Code:
void loadImageData
(uchar
*data,
int rows,
int cols,
QImage *rawImage
) {
uchar* row;
for (int i = 0; i < rows; i++)
{
//access each row of data values
row= rawImage->scanLine(i);
for (int j = 0; j < cols; j++) //width
row[j] =data[i * cols + j] ;
}
}
Thanks for your advice