PDA

View Full Version : renderPixmap



zorro68
1st March 2007, 02:46
Two days ago this code capture perfectly the opengl screen, but now capture a black rectangle:



void Visor::BTNcaptura_click()
{
QSize size = getSize();
if (size.isValid()) {
//QPixmap pixmap = QPixmap::grabWidget(glWidget, 0,0, size.width(), size.height()); <-- this capture a green rectangle
QPixmap pixmap = glWidget->renderPixmap(size.width(), size.height()); <-- this capture a black rectangle
QString fileName = QFileDialog::getSaveFileName(this,tr("Guardar la imagen como..."),QString(),
tr("Archivos de imágenes (*.png *.jpg *.bmp *.jpeg *.ppm *.xbm *.xpm);;Todos los Archivos (*)"));
if (!fileName.isEmpty()){
QString filter=QFileInfo(fileName).suffix();
if (filter=="jpg")
pixmap.save(fileName,"jpg");
...
else
pixmap.save(fileName+".png","png");
}
}
}



What happend?

wysota
1st March 2007, 11:18
Did you do any modifications to your computer during the two days? Drivers update, software update...

jpn
1st March 2007, 11:21
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).



// try
pixmap.save(fileName, "JPG"); // instead of "jpg"
// or
pixmap.save(fileName); // in this case fileName should end with ".jpg"

wysota
1st March 2007, 11:22
Shouldn't it be "JPEG" and not "JPG"?

jpn
1st March 2007, 11:23
Shouldn't it be "JPEG" and not "JPG"?
I'm not sure if it makes any difference: Reading and Writing Image Files (http://doc.trolltech.com/4.2/qpixmap.html#reading-and-writing-image-files)

wysota
1st March 2007, 11:28
Right, looks like it doesn't :) Although the format name is "JPEG" and not "JPG" ;)

minimoog
2nd March 2007, 14:15
Why don't you use QGLWidget::grabFrameBuffer (http://doc.trolltech.com/4.2/qglwidget.html#grabFrameBuffer)()?

zorro68
2nd March 2007, 22:59
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.

zorro68
2nd March 2007, 23:01
One question about the forum.
Green light on near the username is that the user is online?

jacek
3rd March 2007, 00:15
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.

minimoog
3rd March 2007, 01:16
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 (http://doc.trolltech.com/4.2/qglframebufferobject.html)), 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().