Blend modes - wspolrzedne poza zakresem

0

witam otrzymuje taki błąd i nie potrafię zrozumieć dlaczego..

QImage::pixel: coordinate (x,y) out of range , w miejscu x i y są wspolrzedne 
QImage::pixel: coordinate (0,0) out of range
QImage::pixel: coordinate (0,1) out of range
QImage::pixel: coordinate (0,2) out of range
QImage::pixel: coordinate (0,3) out of range
QImage::pixel: coordinate (0,4) out of range
QImage::pixel: coordinate (0,5) out of range
QImage::pixel: coordinate (0,6) out of range
QImage::pixel: coordinate (0,7) out of range
QImage::pixel: coordinate (0,8) out of range

Oto mój kod

#include "mywidget.h"

#include <QPainter>

MyWidget::MyWidget(QWidget *parent) : QWidget(parent)
{
    image = QImage(700, 500, QImage::Format_RGB32);
    image.fill(Qt::black);
    layers[1].setImage(QImage("plaza.png"));
    layers[1].setAlfa(100);
    layers[1].setBlendMode("normal");

    layers[2].setImage(QImage("zamek.png"));
    layers[2].setAlfa(100);
    layers[2].setBlendMode("normal");

    layers[0].setImage(QImage("gradient.png"));
    layers[0].setAlfa(100);
    layers[0].setBlendMode("normal");
    mixLayers();
}

void MyWidget::paintEvent(QPaintEvent*){
    QPainter p(this);
    p.drawImage(0, 0, image);
}

QImage MyWidget::alphaBlending(QImage *image1, QImage *image2, int alfa)
{
    int width = 700;
    int height = 500;
    int r, g, b;
    QImage result = QImage(width, height, QImage::Format_RGB32);
    QColor color, colorImage1, colorImage2;

    for(int x = 0; x < width; x++){
        for(int y = 0; y < height; y++){
            colorImage1 = image1->pixel(x, y);
            colorImage2 = image2->pixel(x, y);
            r = int(colorImage1.red() * (1 - alfa/100.0) + (alfa/100.0) * colorImage2.red());
            g = int(colorImage1.green() * (1 - alfa/100.0) + (alfa/100.0) * colorImage2.green());
            b = int(colorImage1.blue() * (1 - alfa/100.0) + (alfa/100.0) * colorImage2.blue());
            color.setRgb(r, g, b);
            result.setPixelColor(x, y, color);
        }
    }

    return result;
}

void MyWidget::mixLayers()
{
    int width = 700;
    int height = 500;
    QImage temp = QImage(width, height, QImage::Format_RGB32);

    image.fill(Qt::black);
    for(int i = 0; i < 3; i++){
        if(layers[i].getBlendMode() == "normal")
            temp = normalBlend(&image, &layers[i].image);
        else if(layers[i].getBlendMode() == "average")
            temp = averageBlend(&image, &layers[i].image);
        else if(layers[i].getBlendMode() == "multiply")
            temp = multiplyBlend(&image, &layers[i].image);
        else if(layers[i].getBlendMode() == "screen")
            temp = screenBlend(&image, &layers[i].image);
        else if(layers[i].getBlendMode() == "darken")
            temp = darkenBlend(&image, &layers[i].image);
        else if(layers[i].getBlendMode() == "lighten")
            temp = lightenBlend(&image, &layers[i].image);

        image = alphaBlending(&image, &temp, layers[i].getAlfa());
    }
    update();
}

Layer* MyWidget::getLayer(int index)
{
    return layers+index;
}

QImage MyWidget::normalBlend(QImage *, QImage *image2)
{
    int width = 700;
    int height = 500;
    QImage result = QImage(width, height, QImage::Format_RGB32);

    for(int x = 0; x < width; x++){
        for(int y = 0; y < height; y++){
            result.setPixelColor(x, y, image2->pixel(x, y));
        }
    }

    return result;
}

QImage MyWidget::averageBlend(QImage *image1, QImage *image2)
{
    int width = 700;
    int height = 500;
    int r, g, b;
    QImage result = QImage(width, height, QImage::Format_RGB32);
    QColor color, colorImage1, colorImage2;

    for(int x = 0; x < width; x++){
        for(int y = 0; y < height; y++){
            colorImage1 = image1->pixel(x, y);
            colorImage2 = image2->pixel(x, y);
            r = 255 - ( (255-colorImage1.red()) + (255-colorImage2.red()) >> 1 );
            g = 255 - ( (255-colorImage1.green()) + (255-colorImage2.green()) >> 1 );
            b = 255 - ( (255-colorImage1.blue()) + (255-colorImage2.blue()) >> 1 );
            color.setRgb(r, g, b);
            result.setPixelColor(x, y, color);
        }
    }

    return result;
}

QImage MyWidget::multiplyBlend(QImage *image1, QImage *image2)
{
    int width = 700;
    int height = 500;
    int r, g, b;
    QImage result = QImage(width, height, QImage::Format_RGB32);
    QColor color, colorImage1, colorImage2;

    for(int x = 0; x < width; x++){
        for(int y = 0; y < height; y++){
            colorImage1 = image1->pixel(x, y);
            colorImage2 = image2->pixel(x, y);
            r = ( colorImage1.red() * colorImage2.red() ) >> 8;
            g = ( colorImage1.green() * colorImage2.green() ) >> 8;
            b = ( colorImage1.blue() * colorImage2.blue() ) >> 8;
            color.setRgb(r, g, b);
            result.setPixelColor(x, y, color);
        }
    }

    return result;
}

QImage MyWidget::screenBlend(QImage *image1, QImage *image2)
{
    int width = 700;
    int height = 500;
    int r, g, b;
    QImage result = QImage(width, height, QImage::Format_RGB32);
    QColor color, colorImage1, colorImage2;

    for(int x = 0; x < width; x++){
        for(int y = 0; y < height; y++){
            colorImage1 = image1->pixel(x, y);
            colorImage2 = image2->pixel(x, y);
            r =  255 - ( (255 - colorImage1.red() ) * ( 255 - colorImage2.red() ) >> 8);
            g = 255 - ( (255 - colorImage1.green() ) * ( 255 - colorImage2.green() ) >> 8);
            b = 255 - ( (255 - colorImage1.blue() ) * ( 255 - colorImage2.blue() ) >> 8);
            color.setRgb(r, g, b);
            result.setPixelColor(x, y, color);
        }
    }

    return result;
}

QImage MyWidget::darkenBlend(QImage *image1, QImage *image2)
{
    int width = 700;
    int height = 500;
    int r, g, b;
    QImage result = QImage(width, height, QImage::Format_RGB32);
    QColor color, colorImage1, colorImage2;

    for(int x = 0; x < width; x++){
        for(int y = 0; y < height; y++){
            colorImage1 = image1->pixel(x, y);
            colorImage2 = image2->pixel(x, y);

            if(colorImage1.red() < colorImage2.red())
                r = colorImage1.red();
            else
                r = colorImage2.red();

            if(colorImage1.green() < colorImage2.green())
                g = colorImage1.green();
            else
                g = colorImage2.green();

            if(colorImage1.blue() < colorImage2.blue())
                b = colorImage1.blue();
            else
                b = colorImage2.blue();

            color.setRgb(r, g, b);
            result.setPixelColor(x, y, color);
        }
    }

    return result;
}

QImage MyWidget::lightenBlend(QImage *image1, QImage *image2)
{
    int width = 700;
    int height = 500;
    int r, g, b;
    QImage result = QImage(width, height, QImage::Format_RGB32);
    QColor color, colorImage1, colorImage2;

    for(int x = 0; x < width; x++){
        for(int y = 0; y < height; y++){
            colorImage1 = image1->pixel(x, y);
            colorImage2 = image2->pixel(x, y);

            if(colorImage1.red() > colorImage2.red())
                r = colorImage1.red();
            else
                r = colorImage2.red();

            if(colorImage1.green() > colorImage2.green())
                g = colorImage1.green();
            else
                g = colorImage2.green();

            if(colorImage1.blue() > colorImage2.blue())
                b = colorImage1.blue();
            else
                b = colorImage2.blue();

            color.setRgb(r, g, b);
            result.setPixelColor(x, y, color);
        }
    }

    return result;
}

2

Miałem podobnie jak próbowałem załadować nieistniejący obrazek:

#include <QImage>
#include <QString>
#include <QColor>

int main(int argc, char** argv) {
    QColor color;
    color.setRgb(1, 1, 1);

    QImage foo("NIE ISTNIEJE TAKI PLIK.png");

    foo.setPixelColor(0, 0, color);
}

Sprawdź ścieżki w liniach pokroju

layers[1].setImage(QImage("plaza.png"));

Czy się ładują jak trzeba (funkcja is null).

0

hmm zmienilem sciezkie
"C:\Users\Tomasz\Desktop\Qt\blendModes\images\plaza.png"
ale mam takie ostrzezenie:
Bez tytułu.png

1
dcielak napisał(a):

hmm zmienilem sciezkie
"C:\Users\Tomasz\Desktop\Qt\blendModes\images\plaza.png"
ale mam takie ostrzezenie:
Bez tytułu.png

Zgaduję, że musisz escapować slashe na Windowsie ( C:\\Users\\Tomasz\\Desktop\\Qt\\blendModes\\images\\plaza.png)

2

W Qt ścieżki do plików zawsze konwertuj w taki sposób Bracie:

QString path(QDir::fromNativeSeparators("C:\\Users\\Tomasz\\Desktop\\Q\t\blendModes\\images\\plaza.png"));
0

dziękuję za odpowiedzi,to pomogło, ale mimo wszystko kod wciąz nie chce mi się uruchomić mam taki błąd :
1852: Uruchamianie C:\Users\Tomasz\Desktop\Qt\build-blendModes-Desktop_Qt_5_12_1_MinGW_64_bit-Debug\debug\blendModes.exe...
1816: The program has unexpectedly finished.
1816: Wymuszono zakończenie procesu.
1816: C:/Users/Tomasz/Desktop/Qtr/build-blendModes-Desktop_Qt_5_12_1_MinGW_64_bit-Debug/debug/blendModes.exe przerwał pracę.

Kod mam z uczelni i chce go ogarnąc, ale nie rozumiem dlaczego wywala błąd..

1
dcielak napisał(a):

dziękuję za odpowiedzi,to pomogło, ale mimo wszystko kod wciąz nie chce mi się uruchomić mam taki błąd :
1852: Uruchamianie C:\Users\Tomasz\Desktop\Qt\build-blendModes-Desktop_Qt_5_12_1_MinGW_64_bit-Debug\debug\blendModes.exe...
1816: The program has unexpectedly finished.
1816: Wymuszono zakończenie procesu.
1816: C:/Users/Tomasz/Desktop/Qtr/build-blendModes-Desktop_Qt_5_12_1_MinGW_64_bit-Debug/debug/blendModes.exe przerwał pracę.

Kod mam z uczelni i chce go ogarnąc, ale nie rozumiem dlaczego wywala błąd..

Google podpowiada, że to może być brak zainstalowanego Windows 10 SDK (https://stackoverflow.com/questions/42106240/cannot-run-qt-example-in-qt-creator-the-program-has-unexpectedly-finished).

Jak nie, to pozostaje debugger, bo z sam twój komunikat nie mówi wiele więcej ponad "nie działa" i ciężko tu cokolwiek zgadnąć.

0

zainstalowalem to, ale co dalej mam z tym zrobic ? nie moge sie w tym połapac ;/

0

Tylko z tym inne działają bez problemu

0

A co mówi debugger?

0

Ustaw breakpointa i zobacz w którym momencie program się wykrzacza

0
au7h napisał(a):

Ustaw breakpointa i zobacz w którym momencie program się wykrzacza

Na odwrót - usuń wszystkie breakpointy i uruchom program pod debuggerem, po czym zreplikuj sytuację. W momencie jak się program wykrzaczy wybierz opcję, że chcesz debuggować, po czym sprawdzaj stos aż dojdziesz do funkcji i linii która spowodowała wywrotkę.

1 użytkowników online, w tym zalogowanych: 0, gości: 1