I’m trying to render a custom image using QImage for QT but I am not getting anywhere with my code so far. I do not want to load an image from file, I want to use the QImage class and QBrush class and what ever else this entails. I’m not great with rendering in APIs but any help to get me going would be appreciated.
Here is what I got. The only thing I’m really given is the image ‘m_pImage’ object…
m_pImage = new QImage(ImageWidth, ImageHeight, QImage::Format_Indexed8);
m_pImage->setColorCount(255);
Also, I’ve tried to add some stuff like so but this part is not working:
QBrush* br = new QBrush(Qt::gray, Qt::Dense3Pattern);
br->setTextureImage(*m_pImage);
QPainter* paint = new QPainter(m_pImage);
paint->setPen(Qt::NoPen);
paint->setBrush(*br);
paint->drawRect(0, 0, ImageWidth, ImageHeight);
for(int i = 0; i < m_ulImageWidth; i++)
{
for(int j = 0; j < ImageHeight; j++)
{
m_pImage->setPixel(i, j, qRgb(255, 255, 255));
}
}
Setting the background image would be preferable but just getting this image to render the brush style Dense3Pattern would be the best in either case.
Here’s a link to the documentation I’ve been using QT Reference
Thanks in advance!!
Duh, I see my problem now.
So I needed to add all the colors I want to use to my colorTable. After I did that, I was able to start drawing using QImage::setPixel(…).
I guess that’s all there was to it!