Hi everyone. I have a problem, I'm creating a simple Image Processing app, at part of brightness adjustment i can't run this function, when it's called then app will be crashed. I have two forms, one of form is mainwindow, one else is sub form to adjust brightness.
//mainwindow.cpp
void MainWindow::brightnessProcessing(int value)
{
QImage image
= imageLabel
->pixmap
()->toImage
();
int w = image.width();
int h = image.height();
int r, g, b;
for(int i=0; i<h; i++)
for(int j=0; j<w; j++) {
c = image.pixel(i, j);
r = c.red()+value;
g = c.green()+value;
b = c.blue()+value;
image.setPixel(i, j, qRgb(r, g, b));
}
imageLabel
->setPixmap
(QPixmap::fromImage(image
));
}
//mainwindow.cpp
void MainWindow::brightnessProcessing(int value)
{
QImage image = imageLabel->pixmap()->toImage();
int w = image.width();
int h = image.height();
QColor c;
int r, g, b;
for(int i=0; i<h; i++)
for(int j=0; j<w; j++) {
c = image.pixel(i, j);
r = c.red()+value;
g = c.green()+value;
b = c.blue()+value;
image.setPixel(i, j, qRgb(r, g, b));
}
imageLabel->setPixmap(QPixmap::fromImage(image));
}
To copy to clipboard, switch view to plain text mode
//mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QtWidgets>
namespace Ui {
class MainWindow;
}
{
Q_OBJECT
public:
explicit MainWindow
(QWidget *parent
= 0);
~MainWindow();
void brightnessProcessing(int value);
private slots:
..........
private:
Ui::MainWindow *ui;
double scaleFactor;
void scaleImage(double factor);
void adjustScrollBar
(QScrollBar *scrollBar,
double factor
);
};
#endif // MAINWINDOW_H
//mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QtWidgets>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
void brightnessProcessing(int value);
private slots:
..........
private:
Ui::MainWindow *ui;
QImage *image;
QLabel *imageLabel;
QScrollArea *scrollArea;
QScrollBar *scrollBar;
double scaleFactor;
void scaleImage(double factor);
void adjustScrollBar(QScrollBar *scrollBar, double factor);
};
#endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode
//brightnesscontrast.cpp
void BrightnessContrast::on_horizontalSliderBrightness_valueChanged(int value)
{
ui
->lineEditBrightness
->setText
(QString::number(value
));
respond.brightnessProcessing(value);
}
//brightnesscontrast.cpp
void BrightnessContrast::on_horizontalSliderBrightness_valueChanged(int value)
{
ui->lineEditBrightness->setText(QString::number(value));
respond.brightnessProcessing(value);
}
To copy to clipboard, switch view to plain text mode
//brightnesscontrast.h
#ifndef BRIGHTNESSCONTRAST_H
#define BRIGHTNESSCONTRAST_H
#include <QDialog>
#include <QtWidgets>
#include "mainwindow.h"
namespace Ui {
class BrightnessContrast;
}
class BrightnessContrast
: public QDialog{
Q_OBJECT
public:
explicit BrightnessContrast
(QWidget *parent
= 0);
~BrightnessContrast();
private slots:
void on_horizontalSliderBrightness_valueChanged(int value);
void on_horizontalSliderContrast_valueChanged(int value);
private:
Ui::BrightnessContrast *ui;
MainWindow respond;
};
#endif // BRIGHTNESSCONTRAST_H
//brightnesscontrast.h
#ifndef BRIGHTNESSCONTRAST_H
#define BRIGHTNESSCONTRAST_H
#include <QDialog>
#include <QtWidgets>
#include "mainwindow.h"
namespace Ui {
class BrightnessContrast;
}
class BrightnessContrast : public QDialog
{
Q_OBJECT
public:
explicit BrightnessContrast(QWidget *parent = 0);
~BrightnessContrast();
private slots:
void on_horizontalSliderBrightness_valueChanged(int value);
void on_horizontalSliderContrast_valueChanged(int value);
private:
Ui::BrightnessContrast *ui;
MainWindow respond;
};
#endif // BRIGHTNESSCONTRAST_H
To copy to clipboard, switch view to plain text mode
anyhelp!
Bookmarks