瀏覽代碼

Use QImage instead of QPixmap

QPixmap does not work with a QCoreApplication
Marco Nolden 14 年之前
父節點
當前提交
01c9ad8f9e

+ 10 - 1
Libs/DICOM/Core/Testing/Cpp/ctkDICOMImageTest1.cpp

@@ -29,7 +29,10 @@ int ctkDICOMImageTest1( int argc, char * argv [] )
   ctkDICOMImage ctkImage(&dcmtkImage);
 
   QLabel qtImage;
-  qtImage.setPixmap(ctkImage.getPixmap(0));
+  QPixmap pixmap;
+  if ( pixmap.convertFromImage(ctkImage.getImage(0),Qt::AvoidDither) )
+  {
+  qtImage.setPixmap(pixmap);
   qtImage.show();
 
   if (argc > 2 && QString(argv[2]) == "-I")
@@ -38,3 +41,9 @@ int ctkDICOMImageTest1( int argc, char * argv [] )
     }
   return EXIT_SUCCESS;
 }
+  else
+  {
+    std::cerr << "Failed to convert QImage to QPixmap" ;
+    return EXIT_FAILURE;
+  }
+}

+ 6 - 5
Libs/DICOM/Core/ctkDICOMImage.cpp

@@ -90,13 +90,13 @@ DicomImage* ctkDICOMImage::getDicomImage() const
   Q_D(const ctkDICOMImage);
   return d->DicomImage;
 }
-QPixmap ctkDICOMImage::getPixmap(int frame) const
+QImage ctkDICOMImage::getImage(int frame) const
 {
   Q_D(const ctkDICOMImage);
 
   // this way of converting the dicom image to a qpixmap was adopted from some code from
   // the DCMTK forum, posted by Joerg Riesmayer, see http://forum.dcmtk.org/viewtopic.php?t=120
-  QPixmap pixmap;
+  QImage image;
   if ((d->DicomImage != NULL) && (d->DicomImage->getStatus() == EIS_Normal))
   {
     /* get image extension */
@@ -114,11 +114,12 @@ QPixmap ctkDICOMImage::getPixmap(int frame) const
 
     if (d->DicomImage->getOutputData(static_cast<void *>(buffer.data() + offset), length - offset, 8, frame))
     {
-      if (!pixmap.loadFromData(buffer, "PGM", Qt::AvoidDither))
+
+      if (!image.loadFromData( buffer ))
       {
-        logger.error("Pixmap couldn't created");
+        logger.error("QImage couldn't created");
       }
     }
   }
-  return pixmap;
+  return image;
 }

+ 1 - 1
Libs/DICOM/Core/ctkDICOMImage.h

@@ -38,7 +38,7 @@ public:
   explicit ctkDICOMImage(DicomImage* dicomImage, QObject* parent = 0);
   virtual ~ctkDICOMImage();
   DicomImage* getDicomImage() const;
-  QPixmap getPixmap(int frame = 0) const;
+  QImage getImage(int frame = 0) const;
   unsigned long frameCount() const;
   Q_PROPERTY(unsigned long frameCount READ frameCount);