Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to effectively scroll 1024x90000 image in a window?

I have the following UI, where the sonogram (freq+time sound representation) is shown. So the image is not loaded from somewhere, it is drawn by QPainter while reading WAV file.

The UI

My current implementation is a single huge QImage object, where the image is drawn. And on paintEvent(), I draw part of the large QImage on the widget:

QPainter painter(this);
// (int, int, QImage*, int, int)
painter.drawImage(0, 0, *m_sonogram, 0, m_offset);

But, as i know, the QPixmap is optimized for displaying pixmaps on the screen, so should I convert the QImage to a QPixmap after the drawing of the sonogram is done?

Also, is it worth to keep large image as some kind of a linked list of separate QPixmap objects of smaller size and make paintEvent() smarter to operate on a list of smaller objects to avoid Qt's auto-cutting procedures and so on?

When my QImage is large enough, each paintEvent() consuming a lot of CPU.

All kinds of advices are welcome :)

like image 719
pavelkolodin Avatar asked Feb 25 '12 17:02

pavelkolodin


People also ask

How do I make an image scrollable?

The scrolling images were acheived using the HTML <marquee> tag. Using this tag, you can give your images a horizontal scroll (from right to left, left to right) or a vertical scroll (top to bottom, or bottom to top). Note that the <marquee> tag isn't an offical HTML tag (but it is recognized by most modern browsers).

How do I auto scroll multiple images in HTML?

You can easily move images in HTML using <marquee> tag. It is used to create scrolling images either from horizontally left to right or right to left, or vertically top to bottom or bottom to top. By default, image found within the <marquee> tag will scroll from right to left.

How do I add a ScrollBar to a photo?

Setting ScrollBar to an imageCreate a pane to hold the image view such as scroll pane, vBox, etc.. Add a listener to the value property, of the scroll bar. Based on the orientation of the scroll bar, set the X/Y layouts of the layout pane, with the negative of the new value of the scroll bar.


1 Answers

Yes, in my limited experience of Qt app development, if you have a static image (or an infrequently updated image) it's well worth (for performance purposes) creating a QPixmap from it and keeping it around to use via QPainter::drawPixmap in your paintEvent handler.

However, I've never tried doing this with anything larger than about 4Kx4K images, so whether it will work for your enormous image or fall over horribly when you start to stress your graphics memory I couldn't say. I'd certainly try it out before considering adding a complicated tiling system.

like image 127
timday Avatar answered Sep 27 '22 00:09

timday