General scaling algorithm for a paint program

My GUI tool, wxPython provides some methods for implementing a user zoom factor, but the quality is not very good. I am looking for ideas on how to create a zoom function that I know is complicated.

I have a bitmap representing my canvas, which is painted on. This is displayed inside a scrolled window.

The problems that I see: - performance when zooming in and panning around the canvas - difficulties with "real" coordinates and increased coordinates - image quality does not deteriorate when scaling

Using wxPython SetUserScale () in device contexts represents image quality similar to this - this is with a 1px line, at 30% increased.

I am just wondering what are the main steps I should take and the problems that I will encounter. Thanks for any suggestions.

+3
source share
2 answers

You can visualize your scene using OpenGL. You get hardware zooming and panning, which is likely to be very fast. OpenGL has various anti-aliasing filters, and you can use GLSL if you want to create your own filter.

- , .

+2

GraphicsContext?

. GCDC . : dc = wx.GCDC(dc)

! , / .

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

Source: https://habr.com/ru/post/1741692/


All Articles