PyQt - 缩放大图像的函数
我需要一个在 pyqt 中缩放非常大的图像(5000 x 7000 像素)的函数。
我已经尝试过gwenview(用C++和Qt编码的图像查看器)的功能,但它对我来说太难理解。
谢谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我以前也遇到过同样的麻烦,我必须制作一个系统来绘制图片并保存结果。我发现最好的方法是:
1-子类QGraphicView使用子类内的
self.createPixmapItem(QPixmap(self.image),pos)添加像素图
2-也在子类中,重新实现轮子事件,如下所示:
<代码>
defwheelEvent(self, event): # 来自(使用 python 和 pyqt 的快速 GUI 编程)一书的代码。
<代码>
(复制并粘贴 QgraphicView 子类中的函数应该适合您)
我的情况比您的情况更复杂,因为我必须制作一个完整的绘图系统_或注释系统_(缩放,绘制,擦除和撤消。 。ETC )。这就是为什么我必须使用 QgraphicsView ,我很确定有一些更简单的方法可以解决你的问题,但我希望你会发现这很有用。
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.
(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.