Results 1 to 6 of 6

Thread: Loading image with Magick++, displaying with Qt

  1. #1
    Join Date
    Apr 2009
    Posts
    46
    Thanks
    4
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Loading image with Magick++, displaying with Qt

    Hi, I have some problems using Magick++ with Qt. It's almost working, but almost in this case is not acceptable.

    Qt Code:
    1. Magick::Image image;
    2. try {
    3. image.read(qPrintable(fileName));
    4. }
    5. catch (Magick::Exception &error_) {
    6. QMessageBox::warning(this, "Error!", QString("%1").arg(error_.what()));
    7. return QPixmap();
    8. }
    9.  
    10. Magick::Blob blob;
    11. image.write(&blob, "XPM");
    12.  
    13. QPixmap pixmap;
    14. pixmap.loadFromData((char*)blob.data(), "XPM");
    15. return pixmap;
    To copy to clipboard, switch view to plain text mode 
    This code does it's thing, but...
    Qt Code:
    1. image.write(&blob, "XPM");
    To copy to clipboard, switch view to plain text mode 
    takes 4 seconds, and the displayed image looks like lost some of it's quality.

    Qt Code:
    1. Magick::Image image;
    2. try {
    3. image.read(qPrintable(fileName));
    4. }
    5. catch (Magick::Exception &error_) {
    6. QMessageBox::warning(this, "Error!", QString("%1").arg(error_.what()));
    7. return QPixmap();
    8. }
    9.  
    10. QImage img(image.columns(), image.rows(), QImage::Format_RGB32);
    11. Magick::ColorRGB rgb;
    12. for (int x = 0; x < img.width(); x++) {
    13. for (int y = 0; y < img.height(); y++) {
    14. rgb = *image.getPixels(x, y, 1, 1);
    15. QColor color(rgb.redQuantum(), rgb.greenQuantum(), rgb.blueQuantum());
    16. img.setPixel(x, y, color.rgb());
    17. }
    18. }
    19. return QPixmap::fromImage(img);
    To copy to clipboard, switch view to plain text mode 

    There's no noticeable delay now when loading image, but displayed image has wrong colors (gets blue-ish kinda).
    I tested this code also with image 1x1 which had color (R: 183, G: 113, B: 51), but Magick++ returns it as (R: 113, G: 51, B: 51).

    The problems might be more Magick++ related, but perhaps someone knows what's wrong or has managed to load image in other way without problems?

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Loading image with Magick++, displaying with Qt

    why are you using redQuantum() instead of red()?
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  3. #3
    Join Date
    Apr 2009
    Posts
    46
    Thanks
    4
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Loading image with Magick++, displaying with Qt

    It doesn't matter, red() returns 0.0 - 1.0 values, redQuantum() 0 - 255.

    The second code actually works now, but had to recompile library with MAGICKCORE_QUANTUM_DEPTH 8. The first one now crashes program.

  4. #4
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Loading image with Magick++, displaying with Qt

    probably due to format mis-match.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Loading image with Magick++, displaying with Qt

    We have no idea what the original image is or what the output looks like. A bluish hue could come from the original, input colorspace conversion, dithering or an indexed palette. All happening in the Magick code.

  6. #6
    Join Date
    Apr 2009
    Posts
    46
    Thanks
    4
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Loading image with Magick++, displaying with Qt

    In first code, the image doesn't matter, it just takes very very long to write image to BLOB. The displayed image slightly lost quality but wasn't bad afterall. In the second code I gave you original image and the output, it was image of 1 pixel: input (R: 183, G: 113, B: 51), output (R: 113, G: 51, B: 51). The second code works fine now, as I said in previous post.

Similar Threads

  1. Loading Image
    By navi1084 in forum Qt Programming
    Replies: 2
    Last Post: 27th June 2011, 05:07
  2. Displaying an image
    By seltra in forum Newbie
    Replies: 2
    Last Post: 3rd October 2010, 19:30
  3. as displaying an image in a mdi?
    By Lycus HackerEmo in forum Qt Programming
    Replies: 4
    Last Post: 6th July 2010, 12:14
  4. Image Loading
    By kavinsiva in forum Qt Programming
    Replies: 2
    Last Post: 11th August 2009, 08:00
  5. Displaying image
    By Rui in forum Newbie
    Replies: 1
    Last Post: 20th June 2009, 21:15

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.