public static QImage fetchThumbnailImageNow(String imageFilename, QSize size) {
    try {
      QImage img = null;
      if (!imageFilename.equals(SearchRecord.DEFAULT_THUMBNAIL_IMAGE))
        img = FileSystemAccess.getFileSystem().readQImage(imageFilename);
      else img = new QImage(imageFilename);

      /*
      QImage result = (img.width() > size.width()
                 || img.height() > size.height())
                 ? img.scaled(size, Qt.AspectRatioMode.KeepAspectRatio, Qt.TransformationMode.SmoothTransformation)
                 : img.copy();
                 */

      QImage result = null;
      if ((img.width() > size.width() || img.height() > size.height())) {
        result =
            img.scaled(
                size,
                Qt.AspectRatioMode.KeepAspectRatio,
                Qt.TransformationMode.SmoothTransformation);
      } else {
        result = img.copy();
      }

      img.dispose();
      return result;
    } catch (InvalidImageException ie) {
      if (log.isDebugEnabled())
        log.debug("fetchThumbnailImageNow(): could not load image=" + imageFilename);
    } catch (Exception e) {
      log.error("fetchThumbnailImageNow(): error", e);
    }
    return null;
  }
Ejemplo n.º 2
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();
      }
    }