Exemplo n.º 1
1
    public QImage resizeImage(QImage image, QSize newSize) {
      if (image.size() == newSize) return image;

      QImage newImage = new QImage(newSize, QImage.Format.Format_RGB32);
      newImage.fill(new QColor(Qt.GlobalColor.white).rgb());
      QPainter painter = new QPainter(newImage);
      painter.drawImage(new QPoint(0, 0), image);
      painter.end();

      return newImage;
    }
Exemplo n.º 2
0
    public boolean openImage(String fileName) {
      QImage loadedImage = new QImage();
      if (!loadedImage.load(fileName)) return false;

      QSize newSize = loadedImage.size().expandedTo(size());
      loadedImage = resizeImage(loadedImage, newSize);
      image = loadedImage;
      modified = false;
      update();
      return true;
    }
Exemplo n.º 3
0
    public void print() {
      QPrinter printer = new QPrinter(QPrinter.PrinterMode.HighResolution);

      QPrintDialog printDialog = new QPrintDialog(printer, this);
      if (printDialog.exec() == QDialog.DialogCode.Accepted.value()) {
        QPainter painter = new QPainter(printer);
        QRect rect = painter.viewport();
        QSize size = image.size();
        size.scale(rect.size(), Qt.AspectRatioMode.KeepAspectRatio);
        painter.setViewport(rect.x(), rect.y(), size.width(), size.height());
        painter.setWindow(image.rect());
        painter.drawImage(0, 0, image);
        painter.end();
      }
    }