绘图程序通用缩放算法

发布于 2024-08-30 01:39:07 字数 397 浏览 2 评论 0原文

我的 GUI 工具包 wxPython 提供了一些实现用户缩放系数的方法,但是质量不太好。我正在寻找有关如何创建缩放功能的想法,我知道这很复杂。

我有一个代表我绘制的画布的位图。这显示在滚动窗口内。

我预见到的问题: - 放大和平移画布时的性能 -“真实”坐标和放大坐标的困难 - 图像质量不会随缩放而降低

在其设备上下文中使用 wxPython 的 SetUserScale() 可以呈现 图像质量像这样 - 这是一条 1px 线,放大 30%。

我只是想知道我需要采取的一般步骤以及我将遇到的挑战。感谢您的任何建议

My GUI toolkit, wxPython provides some methods for implementing a user zoom factor, however the quality isn't too good. I'm looking for ideas on how to create a zooming feature, which I know is complicated.

I have a bitmap representing my canvas which is drawn to. This is displayed inside a scrolled window.

Problems I forsee:
- performance when zoomed in and panning around the canvas
- difficulties with "real" coordinates and zoomed in coordinates
- image quality not degrading with the zoom

Using wxPython's SetUserScale() on its device contexts presents image quality like this - this is with a 1px line, at 30% zoomed in.

I'm just wondering the general steps I'll need to take and the challenges I'll encounter. Thanks for any suggestions

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

毁梦 2024-09-06 01:39:07

您可以使用 OpenGL 渲染场景。您可以进行硬件缩放和平移,这可能会非常快。 OpenGL 中也提供了各种平滑滤镜,如果您想要自定义滤镜,可以使用 GLSL。

如果您想手动执行操作,请查看双线性插值双三次插值

You can render your scene using OpenGL. You get hardware scaling and panning, which will probably be very fast. There are various smoothing filters available in OpenGL, too, and you can use GLSL if you want a custom filter.

If you want to do things manually, look into bilinear interpolation and bicubic interpolation.

记忆之渊 2024-09-06 01:39:07

您是否尝试过使用GraphicsContext

这是一些示例代码。使用 GCDC 应该很容易放入现有代码中 包装器。你可能只需要这一行:dc = wx.GCDC(dc)

渲染会慢很多!您可以将此设置为可由用户启用/禁用的选项。

替代文本 http://www.michaelfogleman.com/static/images/gcdc.png< /a>

import wx
import random

class Panel(wx.Panel):
    def __init__(self, parent):
        super(Panel, self).__init__(parent, -1)
        self.Bind(wx.EVT_PAINT, self.on_paint)
        self.lines = [[random.randint(0, 500) for i in range(4)] for j in range(100)]
    def on_paint(self, event):
        dc = wx.PaintDC(self)
        dc = wx.GCDC(dc)
        dc.SetUserScale(0.3, 0.3)
        for line in self.lines:
            dc.DrawLine(*line)

class Frame(wx.Frame):
    def __init__(self):
        super(Frame, self).__init__(None, -1, 'Test')
        Panel(self)

if __name__ == "__main__":
    app = wx.PySimpleApp()
    frame = Frame()
    frame.Show()
    app.MainLoop()

Have you tried using GraphicsContext?

Here's some sample code. It should be easy to drop into your existing code using the GCDC wrapper. You may only need the line: dc = wx.GCDC(dc)

Rendering will be a lot slower! You could make this an option that could be enabled/disabled by the user.

alt text http://www.michaelfogleman.com/static/images/gcdc.png

import wx
import random

class Panel(wx.Panel):
    def __init__(self, parent):
        super(Panel, self).__init__(parent, -1)
        self.Bind(wx.EVT_PAINT, self.on_paint)
        self.lines = [[random.randint(0, 500) for i in range(4)] for j in range(100)]
    def on_paint(self, event):
        dc = wx.PaintDC(self)
        dc = wx.GCDC(dc)
        dc.SetUserScale(0.3, 0.3)
        for line in self.lines:
            dc.DrawLine(*line)

class Frame(wx.Frame):
    def __init__(self):
        super(Frame, self).__init__(None, -1, 'Test')
        Panel(self)

if __name__ == "__main__":
    app = wx.PySimpleApp()
    frame = Frame()
    frame.Show()
    app.MainLoop()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文