开发者

PyQt - Function for zooming large Images

I need a function for zooming very large images (5000 x 7000 pixel) in pyqt.

I´ve tried out the functions from gwenview 开发者_开发百科(Image viewer coded in C++ and Qt), but it`s too difficult for me to understand.

Thanks!


i had the same trouble before , i had to make a system to draw over picture and save the result. the best approach i found is to :
1- subclass QGraphicView add a pixmap using : self.createPixmapItem(QPixmap(self.image),pos) inside the subClass
2- in the subclass also , re implement the wheel event like so :
def wheelEvent(self, event): # code from (rapid GUI programming using python and pyqt ) book.

    factor = 1.41 ** (event.delta() / 240.0)
    self.scale(factor, factor)

(copying and pasting the function inside the QgraphicView subclass should work fine for you)

my case was kind of more complicated than your case since i had to make a complete drawing system _ or a comment system _ (Zoom , draw ,erase and undo ..etc ). that's why i had to use the QgraphicsView , im pretty sure that there are some easier ways to do you case but i hope you'll find this usefull .


In my app I have a grid which I hide when the user zooms out beyond a certain point. I acheived this by sending a signal of the zoom level whenever it changes, and catching that in a slot in the scene to enable or diable the grid. You could do the same to switch image files to a lower resolution copy of the image when you're zoomed out beyond a certain point.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜