
Originally Posted by
sar_van81
sorry to ask you the same thing repeatedly.can you say me whats the use of loadFrom Data...?
To load an image from a block of data which is not contained in a file on disk. QImage constructors take a filename as an argument. loadFromData() is just another way of constructing a QImage. It's exactly equivalent to the following constructor:
QImage ( const uchar
* data,
int width,
int height, Format format
)
QImage ( const uchar * data, int width, int height, Format format )
To copy to clipboard, switch view to plain text mode
so which means that if i have a buffer of RGB datas and if i specify the format as "BMP" or any format it will construct an image.is my undersanding correct ...?
No. You have to have the data in the format specified by the format you pass - it has to be a proper BMP image in this case. Maybe this example will help:
QFile bmpfile
("someimage.bmp");
bmpfile.
open(QFile::ReadOnly);
image.loadFromData(contents, "BMP");
QFile bmpfile("someimage.bmp");
bmpfile.open(QFile::ReadOnly);
QByteArray contents = bmpfile.readAll();
QImage image;
image.loadFromData(contents, "BMP");
To copy to clipboard, switch view to plain text mode
As you see you need something more than an actual pixel data - you need everything which is contained in a BMP file (the header containing width, height, colour depth and a colour map in case of indexed images in addition to the pixel data in a proper format (upside down BGR in case of a BMP file) ).
Also i think the function you said is similar to QImage::setPixel wherein we can set each pixel's value usong RGB.
No. setPixel sets a pixel according to the format of an already existing QImage object, it's width and height whereas loadFromData() creates an image from scratch (reading its dimensions and colour depth from the blob).
for this only i'm insisting on loadFromData.
Then don't as it's of no use to you. Use QImage::bits() instead.
is there any suggestions or solutions for displaying image from RGB datas...?
Use QLabel to display your image.
Understand this - "RGB data" doesn't mean anything by itself. The machine has to know how many bytes correspond to a single pixel, what is the order of colour components, the length of the scanline (width of the picture) and what colours should be associated with colour numbers for indexed images. All this data has to be provided in addition to the actual blob of data containing the pixels themselves (which you call "RGB data"). So summarising loadFromData() doesn't only take the blob ("RGB data") itself as an input but also all those other values I mentioned and they have to be provided according to some format understood by QImage.
Bookmarks