Results 1 to 11 of 11

Thread: renderPixmap

  1. #1
    Join Date
    Jan 2007
    Posts
    95
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy renderPixmap

    Two days ago this code capture perfectly the opengl screen, but now capture a black rectangle:

    Qt Code:
    1. void Visor::BTNcaptura_click()
    2. {
    3. QSize size = getSize();
    4. if (size.isValid()) {
    5. //QPixmap pixmap = QPixmap::grabWidget(glWidget, 0,0, size.width(), size.height()); <-- this capture a green rectangle
    6. QPixmap pixmap = glWidget->renderPixmap(size.width(), size.height()); <-- this capture a black rectangle
    7. QString fileName = QFileDialog::getSaveFileName(this,tr("Guardar la imagen como..."),QString(),
    8. tr("Archivos de imágenes (*.png *.jpg *.bmp *.jpeg *.ppm *.xbm *.xpm);;Todos los Archivos (*)"));
    9. if (!fileName.isEmpty()){
    10. QString filter=QFileInfo(fileName).suffix();
    11. if (filter=="jpg")
    12. pixmap.save(fileName,"jpg");
    13. ...
    14. else
    15. pixmap.save(fileName+".png","png");
    16. }
    17. }
    18. }
    To copy to clipboard, switch view to plain text mode 


    What happend?
    Last edited by jacek; 1st March 2007 at 21:02. Reason: wrapped too long line

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: renderPixmap

    Did you do any modifications to your computer during the two days? Drivers update, software update...

  3. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: renderPixmap

    Have you verified that getSize() returns what it's supposed to? What happens if you pass the image format as uppercases or even leave it out (in 4.2 it's a default parameter defaulting to 0 when the image format is guessed based on the passed filename extension).

    Qt Code:
    1. // try
    2. pixmap.save(fileName, "JPG"); // instead of "jpg"
    3. // or
    4. pixmap.save(fileName); // in this case fileName should end with ".jpg"
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: renderPixmap

    Shouldn't it be "JPEG" and not "JPG"?

  5. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: renderPixmap

    Quote Originally Posted by wysota View Post
    Shouldn't it be "JPEG" and not "JPG"?
    I'm not sure if it makes any difference: Reading and Writing Image Files
    J-P Nurmi

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: renderPixmap

    Right, looks like it doesn't Although the format name is "JPEG" and not "JPG"

  7. #7
    Join Date
    Feb 2007
    Posts
    49
    Thanks
    4
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: renderPixmap

    Why don't you use QGLWidget::grabFrameBuffer()?

  8. #8
    Join Date
    Jan 2007
    Posts
    95
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: renderPixmap

    wysota: This is not the problem because i have not modified my computer.
    wysota and jpn: If i used upper letter dont work.
    minimoog: Because I need to resize image.

    I know whats the problem but I dont know how to correct it. The problem is that if i create an object at first (in this function initializeGL()) works fine, but if i create an object from a file after initializeGL() dont work.

    I have read that renderPixmap run initializeGL, PaintGL and resizeGL, and thats the problem. I create an object out of this functions (reading from a file).

    I wish i explain well.

  9. #9
    Join Date
    Jan 2007
    Posts
    95
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: renderPixmap

    One question about the forum.
    Green light on near the username is that the user is online?

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: renderPixmap

    Quote Originally Posted by zorro68 View Post
    One question about the forum.
    Green light on near the username is that the user is online?
    Yes, just like the tooltip says.

    Please, next time ask such questions in more appropriate place, like Feedback section.
    Last edited by jacek; 3rd March 2007 at 02:22.

  11. #11
    Join Date
    Feb 2007
    Posts
    49
    Thanks
    4
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: renderPixmap

    Heh, you can use OpenGL to resize image for free (in your case just change the viewport). Or you can use render_to_texture (Framebuffer Object), or you can read directly the pixels with glReadPixels.

    Anyway, if you use renderPixmap, make sure that OpenGL initialization code (like setting perspective matrices, display lists) are in InitializeGL().

Similar Threads

  1. renderPixmap and texture
    By techno in forum Qt Programming
    Replies: 1
    Last Post: 2nd March 2006, 12:13

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.