//implemation to1bit
#include"to1bit.h"
#include"grayscale.h"
To1bit::To1bit()
:QObject(){
}
To1bit::~To1bit(){}
void To1bit::slotTo1bit(QImage* img, int border){
QRgb color;
GrayScale gr;
gr.toGrayScale(img);
for(int y=0; y<img->height(); y++){
for(int x=0; x<img->width(); x++){
color = img->pixel(x,y);
if(qRed(color) < border){
img->setPixel(x,y, qRgb(0,0,0));
}else{
img->setPixel(x,y, qRgb(255,255,255));
}
}
}
}
//
//to1bit dialog
//
To1bitDlg::To1bitDlg(QWidget* parent, const char* name, bool modal)
:QDialog(parent, name, modal){
_slider = new QSlider(0,255,5,128,Horizontal,this,"dialog");
_edit = new QLineEdit("128", this, "dialog");
_bnOk = new QPushButton("OK", this, "dialog");
_bnCancel = new QPushButton("Cancel", this, "dialog");
setCaption("to 1bit");
resize(260,70);
_slider->setGeometry(10,10,200,20);
_edit->setGeometry(220,10,30,20);
_bnOk->setGeometry(140,40,40,20);
_bnCancel->setGeometry(190,40,60,20);
connect(_slider, SIGNAL(valueChanged(int)),
this, SLOT(setValue(int)));
connect(_bnCancel, SIGNAL(clicked()), this, SLOT(reject()) );
connect(_bnOk, SIGNAL(clicked()), this, SLOT(accept()) );
}
To1bitDlg::~To1bitDlg(){}
void To1bitDlg::setValue(int value){
QString str;
_edit->setText(str.setNum(value,10));
}
int To1bitDlg::data(){
QString str = _edit->text();
return str.toInt(0,10);
}