Results 1 to 3 of 3

Thread: Individual Pixel manipulation with QImage = Black Lines?

  1. #1
    Join Date
    Jun 2011
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Individual Pixel manipulation with QImage = Black Lines?

    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).


    Qt Code:
    1. #include "widget.h"
    2. #include "ui_widget.h"
    3.  
    4. #include <QPainter>
    5. #include <QPaintDevice>
    6. #include <QLabel>
    7. #include <iostream>
    8. #include <QImage>
    9. #include <QPixmap>
    10.  
    11. using namespace std;
    12.  
    13.  
    14. Widget::Widget(QWidget *parent) :
    15. QWidget(parent),
    16. ui(new Ui::Widget)
    17. {
    18. ui->setupUi(this);
    19.  
    20.  
    21. for(int i=0;i<100;i++)
    22. {
    23. for(int j=0;j<100;j++)
    24. {
    25.  
    26.  
    27. myimage = QImage(100,100,QImage::Format_RGB32);
    28. QRgb colorval;
    29. colorval = qRgb(i,j,50);
    30.  
    31. myimage.setPixel(j,i,colorval);
    32. cout << " Setting " << i << " " << j << endl;
    33.  
    34.  
    35.  
    36. }
    37.  
    38.  
    39. }
    40.  
    41.  
    42.  
    43.  
    44. QPixmap mypixmap = QPixmap::fromImage(myimage);
    45. mylabel = new QLabel;
    46. mylabel->setPixmap(mypixmap);
    47. mylabel->setScaledContents(true);
    48. mylabel->show();
    49.  
    50.  
    51. }
    52.  
    53. Widget::~Widget()
    54. {
    55. delete ui;
    56. }
    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,

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Individual Pixel manipulation with QImage = Black Lines?

    You are reinitializing the image in every iteration of the loop. Are you sure this is what you want?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jun 2011
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Individual Pixel manipulation with QImage = Black Lines?

    Taking that out of the loops solved the problem with the lines, thanks.

Similar Threads

  1. Replies: 8
    Last Post: 29th July 2011, 15:54
  2. Replies: 3
    Last Post: 12th November 2010, 18:08
  3. QImage.pixel and Format_Indexed8
    By chef_seppel in forum Newbie
    Replies: 2
    Last Post: 29th September 2010, 23:17
  4. Shifting a QImage up by 1 pixel row
    By MSUdom5 in forum Qt Programming
    Replies: 2
    Last Post: 7th May 2010, 11:25
  5. QImage Pixel Coordinations
    By strateng in forum Newbie
    Replies: 2
    Last Post: 6th May 2010, 11:00

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.