增加按像素切割图片
This commit is contained in:
parent
cd947cc7f7
commit
ed421b60d3
|
@ -1244,7 +1244,7 @@ void MainWindow::on_action_slice_triggered()
|
|||
lineEdit->setText(sn);
|
||||
hbox->addWidget(lineEdit);
|
||||
vbox->addLayout(hbox);
|
||||
label = new QLabel;
|
||||
label = new QLabel(":分隔按像素切割");
|
||||
label->setAlignment(Qt::AlignCenter);
|
||||
vbox->addWidget(label);
|
||||
connect(comboBox, &QComboBox::currentTextChanged, [=]{
|
||||
|
@ -1265,30 +1265,65 @@ void MainWindow::on_action_slice_triggered()
|
|||
dialog->show();
|
||||
|
||||
connect(pushButton_confirm, &QPushButton::clicked, [=]{
|
||||
bool b;
|
||||
int n = lineEdit->text().toInt(&b, 10);
|
||||
if (b) {
|
||||
for (int i=0; i<n; i++) {
|
||||
if (!lineEdit->text().contains(":")) {
|
||||
bool b;
|
||||
int n = lineEdit->text().toInt(&b, 10);
|
||||
if (b) {
|
||||
for (int i=0; i<n; i++) {
|
||||
QImage image;
|
||||
if (comboBox->currentIndex() == 0) {
|
||||
int dy = imageWidget->image.height() / n;
|
||||
image = imageWidget->image.copy(0, dy * i, imageWidget->image.width(), dy);
|
||||
} else if (comboBox->currentIndex() == 1) {
|
||||
int dx = imageWidget->image.width() / n;
|
||||
image = imageWidget->image.copy(dx * i, 0, dx, imageWidget->image.height());
|
||||
}
|
||||
QString fp = "";
|
||||
if (path == "")
|
||||
fp = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation) + "/" + comboBox->currentText() + QString::number(i) + ".png";
|
||||
else
|
||||
fp = QFileInfo(path).path() + "/" + QFileInfo(filename).baseName() + comboBox->currentText() + QString::number(i) + "." + QFileInfo(filename).suffix();
|
||||
//qDebug() << fp;
|
||||
image.save(fp, nullptr, 100);
|
||||
label->setText("等分切割:" + comboBox->currentText() + " " + QString::number(i+1) + "/" + QString::number(n));
|
||||
}
|
||||
settings.setValue("Slice", lineEdit->text());
|
||||
} else {
|
||||
QMessageBox::critical(dialog, "错误", "份数不是数字");
|
||||
}
|
||||
} else {
|
||||
QStringList SL = lineEdit->text().split(":");
|
||||
int x=0, y=0;
|
||||
for (int i=0; i<SL.length(); i++) {
|
||||
QImage image;
|
||||
if (comboBox->currentIndex() == 0) {
|
||||
int dy = imageWidget->image.height() / n;
|
||||
image = imageWidget->image.copy(0, dy * i, imageWidget->image.width(), dy);
|
||||
bool b;
|
||||
int dy = SL.at(i).toInt(&b, 10);
|
||||
if (b) {
|
||||
image = imageWidget->image.copy(0, y, imageWidget->image.width(), dy);
|
||||
y += dy;
|
||||
} else {
|
||||
QMessageBox::critical(dialog, "错误", SL.at(i) + " 不是数字");
|
||||
}
|
||||
} else if (comboBox->currentIndex() == 1) {
|
||||
int dx = imageWidget->image.width() / n;
|
||||
image = imageWidget->image.copy(dx * i, 0, dx, imageWidget->image.height());
|
||||
bool b;
|
||||
int dx = SL.at(i).toInt(&b, 10);
|
||||
if (b) {
|
||||
image = imageWidget->image.copy(x, 0, dx, imageWidget->image.height());
|
||||
x += dx;
|
||||
} else {
|
||||
QMessageBox::critical(dialog, "错误", SL.at(i) + " 不是数字");
|
||||
}
|
||||
}
|
||||
QString fp = "";
|
||||
if (path == "")
|
||||
fp = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation) + "/" + comboBox->currentText() + QString::number(i) + ".png";
|
||||
else
|
||||
fp = QFileInfo(path).path() + "/" + QFileInfo(filename).baseName() + comboBox->currentText() + QString::number(i) + "." + QFileInfo(filename).suffix();
|
||||
//qDebug() << fp;
|
||||
image.save(fp, nullptr, 100);
|
||||
label->setText("切割:" + comboBox->currentText() + " " + QString::number(i+1) + "/" + QString::number(n));
|
||||
label->setText("像素切割:" + comboBox->currentText() + " " + QString::number(i+1) + "/" + QString::number(SL.length()));
|
||||
}
|
||||
settings.setValue("Slice", lineEdit->text());
|
||||
} else {
|
||||
QMessageBox::critical(dialog, "错误", "份数不是数字");
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue