Can anybody tell me how i can format my array so i can load it to a QImage? For now i have a 2d-char-array:
uchar dataArray[400][400];
time_t t;
srand(time(&t));
int x, y;
for(x=0; x< 400; x++)
{
for(y=0; y<400; y++)
{
dataArray[x][y] = rand()%1001;
}
}
QPainter MyPainter(this);
scene = new QGraphicsScene(this);
scene->addEllipse(200, 200, 20, 20);
ui.graphicsView->setScene(scene);
*image = new QImage(*dataArray, 400, 400, QImage::Format_Mono);
image->setColorCount(2);
image->setColor(1, qRgb(255, 0, 0));//red
image->setColor(0, Qt::transparent);
scene->addPixmap(QPixmap::fromImage(*image));
When the content of the array is 0 I want the one color and content > 0 the other color. So i want to load the array into a monochromatic QImage. Obviously this array does not work. How does the Array need to be formatted for my QImage to load properly? The doc just says following, but i do not really get what that means...
data must be 32-bit aligned, and each scanline of data in the image must also be 32-bit aligned.
I want a QImage with Format_Mono like this Where "x" and "+" represent single pixels with different color (red and transparent):
xxxx+xxx++xxx
xxx++xx++xxxx
++x+x+xxxxxxx
+xxx+x+x+x+xx
For this i have an array (dataArray as in code above) with same pattern where x is above a specified value and + is under or equal (the value is 0 at the moment). How do i convert this array to an array wich can be used by QImage with Format_Mono so i can see the correct pattern?
dataArray
? – Marek R