本文介绍了绘图程序的通用缩放算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

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

在其设备上下文中使用wxPython的SetUserScale()会显示-这是一条1px的线,放大了30%。

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

推荐答案

您是否尝试过使用?

Have you tried using GraphicsContext?

以下是一些示例码。使用包装器。您可能只需要以下行: dc = wx.GCDC(dc)

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.

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()

这篇关于绘图程序的通用缩放算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-03 23:18
查看更多