I've already seen these ( http://doc.trolltech.com/4.2/qimage.html#image-formats and http://doc.trolltech.com/4.2/qimage....l-manipulation ) but I do not know what appropiate image conversions I should use for JPEG PNG ang BMP files.

See the attached image,

i am trying to create a grayscaled image (right QGraphicsView) of a raw image (left QGraphicsView). The right QGraphics View is applied with the following function. After the following function is applied to the right QGraphicsView, the right QGraphicsView's image shall have been grayscaled but something is wrong, the white pixels become blue.


Qt Code:
  1. void MainWindow::doF3()
  2. {
  3. QString fileName = QFileDialog::getOpenFileName(this,
  4. tr("Open Image"), QDir::currentPath());
  5. if (!fileName.isEmpty()) {
  6. QImage tempImage(fileName);
  7.  
  8. if (tempImage.isNull()) {
  9. QMessageBox::information(this, tr("Load Warning"),
  10. tr("Cannot load %1.").arg(fileName));
  11. return;
  12. }
  13. //loadedImage is a globally declared variable
  14. loadedImage = tempImage;
  15.  
  16. //Here is one problem, I do not know what appropriate conversions I will do for reading JPEG PNG BMP
  17. QImage image = tempImage.convertToFormat(QImage::Format_ARGB32_Premultiplied);
  18. int pixel = 0;
  19. int gray = 0;
  20. int alpha = 0;
  21. int x = 0;
  22. int y = 0;
  23. for (x= 0; x < image.width(); x++){
  24. for (y = 0; y < image.height(); y++){
  25. pixel = image.pixel(x, y);
  26. gray = qGray(pixel);
  27. alpha = qAlpha(pixel);
  28.  
  29. //Here is another problem, I do not know how to test if this makes the pixel grayscaled
  30. image.setPixel(x, y, qRgba(qRed(gray), qGreen(gray), qBlue(gray), alpha));
  31.  
  32. }
  33. }
  34.  
  35.  
  36. //add the scene with grayscaled image to the right QGraphicsView
  37.  
  38. graphicsViewVis->setScene(scene);
  39.  
  40. graphicsViewVis->show();
  41. }
  42. }
To copy to clipboard, switch view to plain text mode