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

  • 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 = 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) );
        if(c == 0 && m == 0 && y == 0 && k == 0) //then we have black as color and then we draw the color blue
        else // then we draw from the background image
    //adding new image to the graphicsScene
    QGraphicsPixmapItem item( QPixmap::fromImage(world));
    QGraphicsScene* scene = new QGraphicsScene;
    QGraphicsView view(scene);


    Is this a wrong way or what is wrong?

    thanks already,

  • Moderators

    welcome to devnet

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

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

  • Moderators

    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.

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

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.