PDA

View Full Version : QPixmap and QVariant



cafu
23rd October 2009, 09:07
Hi everybody,

I am working on a software that is using an active x control. The active x has function that return a bitmap as QVariant, tha Qvariant Type is QvariantList, and the item type inside the list are reconigzes as int.

The Function is suppose to return this information wrap in a variant:


BitmapInfoHeader: (WINDOWS BITMAPINFOHEADER sturct);
Palette 256 element arrayof Windows PALETTEENTRY;
Bits Two-Dimensional array of byte. the size of the array is specified in the bitmapInfoHeader.bSizeImage


Well this is what i am doing:



QVariantList list = ActiveXObject->Bitmap().toList();
uchar unChList[list.size()];
for (qint32 i = 0; i < list.size(); i++)
{
unChList[i] = a.at(i).toUInt();
}
QPixmap pixBeam;
pixBeam.loadFromData(unChList, list.size());
QString name = "File.pdf";
QPrinter printer;
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setOutputFileName(name);
printer.setPageSize(QPrinter::A4);
printer.setPageMargins(25, 10, 20, 10, QPrinter::Millimeter);
printer.setFullPage(false);

QPainter painter;
if (!painter.begin(&printer))
{
qWarning("failed to open file, is it writable?");
return;
}
painter.setWindow(0, 0, 1650, 2750);

QPen pen;
pen.setBrush(QBrush(Qt::black, Qt::SolidPattern));
painter.setPen(pen);

/*********
*here i draw also some rects and text
*********/

painter.drawPixmap(QRect(0, 100, 1650, 1200), pixBeam, pixBeam.rect());

/*********
*here i draw also some rects and text
*********/
painter.end();


:confused:
The text and and squares and lines are there but the bitmap is not.
How shall i conver this? i calling "fromData" function in a incorrect way?:crying:

Thanks for the help in Advance

PS: I have run with the printing of the value they have data inside.

kwisp
23rd October 2009, 09:23
why do you not use format in bool QPixmap::loadFromData ( const uchar * data, uint len, const char * format = 0, Qt::ImageConversionFlags flags = Qt::AutoColor )
what does this function return? true or false?

cafu
23rd October 2009, 10:08
I think this is the function that i am using but i am not checking the return value,

I will check and let you know

cafu
23rd October 2009, 10:51
The function returns false

Some one can give a hint what to do... :crying:

kwisp
23rd October 2009, 11:04
and why do you not use foramat argument ?
"JPG"
"PNG"
etc...

cafu
23rd October 2009, 11:22
i am trying know with the argument and see?

the things is to make a testi have to run it for around 15 min to wait for the active x to create the bitmap.

cafu
23rd October 2009, 11:23
But do i need to send header and the palette or just the bits..?

please help!!!!!!!!!!!!!!!!


:eek::eek::eek:

cafu
27th October 2009, 10:07
So have someone Idea how to work aroud this problem, thanks

wysota
27th October 2009, 10:27
QVariantList list = ActiveXObject->Bitmap().toList();
What is this supposed to do? What is the variable "a"? What does it contain?

cafu
27th October 2009, 10:33
Sorry it was a typo it should be "list" which contains the bitmap.



QVariantList list = ActiveXObject->Bitmap().toList();
uchar unChList[list.size()];
for (qint32 i = 0; i < list.size(); i++)
{
unChList[i] = list.at(i).toUInt();
}
QPixmap pixBeam;
pixBeam.loadFromData(unChList, list.size());
QString name = "File.pdf";
QPrinter printer;
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setOutputFileName(name);
printer.setPageSize(QPrinter::A4);
printer.setPageMargins(25, 10, 20, 10, QPrinter::Millimeter);
printer.setFullPage(false);

QPainter painter;
if (!painter.begin(&printer))
{
qWarning("failed to open file, is it writable?");
return;
}
painter.setWindow(0, 0, 1650, 2750);

QPen pen;
pen.setBrush(QBrush(Qt::black, Qt::SolidPattern));
painter.setPen(pen);

/*********
*here i draw also some rects and text
*********/

painter.drawPixmap(QRect(0, 100, 1650, 1200), pixBeam, pixBeam.rect());

/*********
*here i draw also some rects and text
*********/
painter.end();

wysota
27th October 2009, 10:43
Are you sure this conversion is valid? What does ActiveXObject->Bitmap() return? Are you sure it is QVariantList compatible? What happens if you use this instead?

QByteArray ba = ActiveXObject->Bitmap().toByteArray();
QPixmap pixmap(ba.constData());

cafu
27th October 2009, 10:51
The array is empty

cafu
27th October 2009, 10:52
and in when i called the function QVariant::typeName, it return QVariantList.


But i will try again and i will let you know, do i have to send everthing with the headers and so on?

wysota
27th October 2009, 12:22
I don't want your code, I won't be able to run it anyway as I'm using Linux. Just tell me what ActiveXObject->Bitmap() is meant to return. Also what is the size of the variant list?

cafu
27th October 2009, 12:41
Sorry for the missunderstood, but this is the information that i have:

The Function is suppose to return this information wrap in a variant:

* BitmapInfoHeader: (WINDOWS BITMAPINFOHEADER sturct);
* Palette 256 element array of Windows PALETTEENTRY;
* Bits Two-Dimensional array of byte. the size of the array is specified in the bitmapInfoHeader.bSizeImage

This activeX is meant to work with labview or visual basic, but i have used the aciveQt example of qutlook to be able to use this with QT.

wysota
27th October 2009, 13:05
So why would you expect QPixmap to be able to load that directly?


QVariantList vlist = ActiveXObject->Bitmap().toList();
BITMAPINFOHEADER header = yourConvertFunc1(vlist.at(0));
// here you have to convert PALETTEENTRY to QRgb
QVector<QRgb> colortable = yourConvertFunc2(vlist.at(1));
int hei = header.???;
int wid = header.???;
const char **rawData = yourConvertFunc3(vlist.at(2));
QByteArray data;
for(int i=0;i<hei;++i){
data.append(rawData[i], wid);
}
QImage image(wid, hei, QImage::Format_Indexed8); // or whatever else format this is
memcpy(image.bits(), data.constData(), data.size()); // alternatively you can copy line by line instead of using an intermediate byte array
image.setColorTable(colortable); // if needed
QPixmap px = QPixmap::fromImage(image);

cafu
27th October 2009, 13:23
I am sorry if perhaps the question or the problem is not the adequate for the forum.

But i am here trying to find a solution to a problem that i have not been able to solve on my own. I am no comming here to post after the first try. i post when i think that maybe someone can help me or has face before the problem, and has idea of this.

About the load directly, well from the documentation is no clear("for me") what it should be send in the data. And I do not know if the header of the bitmap is need it.

The aproach that you said is no working cuase the size of the variantList is a lot bigger than that. I tryed something similar a first. then i tryed this one, trying to conpy the memory values into the variables.



QVariantList list = M2XObject->BeamBitmap().toList();
BITMAPINFOHEADER header;
PALETTEENTRY palette;
uchar chHeader[sizeof(BITMAPINFOHEADER)];
uchar chPalette[sizeof(PALETTEENTRY)];
qint32 i = 0;
for (quint32 k = 0; k < sizeof(BITMAPINFOHEADER); k++)
{
chHeader[k] = list.at(i).toInt();
i++;
}
mencpy(header,chHeader,sizeof(BITMAPINFOHEADER));
for (quint32 k = 0; k < sizeof(PALETTEENTRY); k++)
{
chPalette[k] = list.at(i).toInt();
i++;
}
quint32 bitsSize=a.size()-sizeof(PALETTEENTRY)-sizeof(BITMAPINFOHEADER);
uchar chBits[si];
for (quint32 k = 0; k < bitsSize; k++)
{
chBits[k] = list.at(i).toInt();
i++;
}
if (!pixBeam.loadFromData(chBits, bitsSize, "BMP"))
{
qWarning("loadFromData false");
}


I will try to make a merge betwen the code you offer me and the one before, and i hope i will work as i need.

Thanks, and i will let know if this work....