Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] Drawing a new image from 2 images and check if it is black
Forum Updated to NodeBB v4.3 + New Features

[Solved] Drawing a new image from 2 images and check if it is black

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 2.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    icon444
    wrote on last edited by
    #1

    Hey,

    I'm pretty new to Qt and I've writting some code that must do this:

    I have two images and I want to create a new image, the new image is a merge of the two. If image 1 has black then the new image will have on that spot blue color otherwise it should be from the original code.

    This is my code but it doens't work.

    @ int c, m, y, k, al;
    QColor color;
    QColor drawColor;
    QImage background;
    QImage world;
    QSize sizeImage;
    int height, width;

    background.load("Background.jpg");
    background = background.convertToFormat(QImage::Format_ARGB32);
    QPainter painter(&world);
    sizeImage = background.size();
    width = sizeImage.width();
    for(int i = 0; i < width; i++)
    {
        color = QColor::fromRgb (background.pixel(50,50) );
        color.getCmyk(&c,&m,&y,&k,&al);
    
        if(c == 0 && m == 0 && y == 0 && k == 0) //then we have black as color and then we draw the color blue
        {
            drawColor.setBlue(255);
            painter.setPen(drawColor);
            painter.drawPoint(i,i);
        }
        else // then we draw from the background image
        {
            drawColor.setCmyk(c,m,y,k,al);
            painter.setPen(drawColor);
            painter.drawPoint(i,i);
        }
    
    }
    
    //adding new image to the graphicsScene
    QGraphicsPixmapItem item( QPixmap::fromImage(world));
    QGraphicsScene* scene = new QGraphicsScene;
    scene->addItem(&item);
    
    QGraphicsView view(scene);
    view.show();
    

    @

    Is this a wrong way or what is wrong?

    thanks already,

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      welcome to devnet

      You might want to check in the debugger, if all components for "black" pixels are at any time set to zero.

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • I Offline
        I Offline
        icon444
        wrote on last edited by
        #3

        In my console I get this:

        QPainter::setPen: Painter not active
        QPainter::drawPoints: Painter not active

        And what exactly do I need to check in the debugger?

        EDIT: I've seen in the debugger nothing looks wrong I think. Why is the painter not drawning something? Also is my for lus correct? Or Do I need 2 for lussen because I don't know if QImage is 2D array or 1D array.

        1 Reply Last reply
        0
        • K Offline
          K Offline
          koahnig
          wrote on last edited by
          #4

          Actually it is quite helpful to give us the error messages instead of just asking where is the problem ;-)

          You construct a null image and then you try to write on it see "constructor":http://developer.qt.nokia.com/doc/qt-4.8/qimage.html#QImage
          The application does not know where to write your pixel. Try to create QImage with a suitable size.

          Vote the answer(s) that helped you to solve your issue(s)

          1 Reply Last reply
          0
          • I Offline
            I Offline
            icon444
            wrote on last edited by
            #5

            Solved thanks. That was the problem that it was a null image.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved