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;
ui(new Ui::Widget)
{
ui->setupUi(this);
for(int i=0;i<100;i++)
{
for(int j=0;j<100;j++)
{
QRgb colorval;
colorval = qRgb(i,j,50);
myimage.setPixel(j,i,colorval);
cout << " Setting " << i << " " << j << endl;
}
}
mylabel->setPixmap(mypixmap);
mylabel->setScaledContents(true);
mylabel->show();
}
Widget::~Widget()
{
delete ui;
}
#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;
}
To copy to clipboard, switch view to plain text mode
From this code I expect each pixel to be colorized and not what actually occurs (See image):
screencap.jpg
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,
Bookmarks