PyQt - 缩放大图像的函数

发布于 2024-09-24 19:24:21 字数 115 浏览 0 评论 0原文

我需要一个在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

自演自醉 2024-10-01 19:24:21

我以前也遇到过同样的麻烦,我必须制作一个系统来绘制图片并保存结果。我发现最好的方法是:
1-子类QGraphicView使用子类内的self.createPixmapItem(QPixmap(self.image),pos)添加像素图
2-也在子类中,重新实现轮子事件,如下所示:
<代码>
defwheelEvent(self, event): # 来自(使用 python 和 pyqt 的快速 GUI 编程)一书的代码。

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

<代码>
(复制并粘贴 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.

    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 .

冰魂雪魄 2024-10-01 19:24:21

在我的应用程序中,我有一个网格,当用户缩小到超出某个点时,我会隐藏该网格。我通过在缩放级别发生变化时发送缩放级别信号并在场景中的插槽中捕获该信号来启用或禁用网格来实现这一点。当缩小超过某个点时,您可以执行相同的操作,将图像文件切换为图像的较低分辨率副本。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文