PDA

View Full Version : Individual Pixel manipulation with QImage = Black Lines?



mkmartin06
9th June 2011, 23:31
Hello all,

I'm working towards a more complex use for QImage and QPixmap, but for now I'm still trying to overcome this fundamental issue I see:

I am using this short code below with QT4 to show a Pixmap via a QLabel, but what I see is only half correct (see code and image below).



#include "widget.h"
#include "ui_widget.h"

#include <QPainter>
#include <QPaintDevice>
#include <QLabel>
#include <iostream>
#include <QImage>
#include <QPixmap>

using namespace std;


Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);


for(int i=0;i<100;i++)
{
for(int j=0;j<100;j++)
{


myimage = QImage(100,100,QImage::Format_RGB32);
QRgb colorval;
colorval = qRgb(i,j,50);

myimage.setPixel(j,i,colorval);
cout << " Setting " << i << " " << j << endl;



}


}




QPixmap mypixmap = QPixmap::fromImage(myimage);
mylabel = new QLabel;
mylabel->setPixmap(mypixmap);
mylabel->setScaledContents(true);
mylabel->show();


}

Widget::~Widget()
{
delete ui;
}


From this code I expect each pixel to be colorized and not what actually occurs (See image):

6560

Can anyone please explain to me the reason these black lines are present in my image?

If i and j are swapped, the lines become horizontal. Additionally, if a second loop is added with (i+1, j+1) the lines are covered.

Thank you,

wysota
10th June 2011, 11:00
You are reinitializing the image in every iteration of the loop. Are you sure this is what you want?

mkmartin06
10th June 2011, 15:16
Taking that out of the loops solved the problem with the lines, thanks.