Seite 1 von 1

Lupen Effekt

Verfasst: Mittwoch 17. Januar 2007, 02:20
von Alexci
Hallo,

Kann man einen Lupen Effekt machen? Wenn man ueber ein Bild im scrolledwindow1 mit der maus geht soll sich im sashWindow1 eine vergroesserung (3 mal) des Bildes anzeigen. Die bilder im scrolledwindow1 werden sehr oft neu aktualisiet (geblinkt) also soll immer das aktuelle Bild vergroessert werden.


Code: Alles auswählen

# -*- coding: cp1250 -*-
import wx 
import wx.lib.scrolledpanel as scrolled
import wx.lib.buttons


class MyFrame(wx.Frame):
    def __init__(self, parent = None, id = -1, title = "",
                 size = wx.Size(1000, 750)): 
        wx.Frame.__init__(self, parent, id, title= '',
                          pos = wx.Point(0, 0), size = size)

        self.statusbar=self.CreateStatusBar()
        self.sashWindow1 = wx.SashWindow(self, name='sashWindow1', pos=wx.Point(820, 24), size=wx.Size(152, 128),
                                         style=wx.CLIP_CHILDREN | wx.SW_3D)
    
        self.scrolledWindow1 = wx.ScrolledWindow(self, name='scrolledWindow', pos=wx.Point(0, 24), size=wx.Size(780, 550), style=wx.HSCROLL | wx.VSCROLL)
        self.scrolledWindow1.SetBackgroundColour(wx.Colour(0, 90, 159))
        self.scrolledWindow1.SetScrollbars(1,1, 3000, 2000)
        self.scrolledWindow1.SetScrollRate(40,40)


        self.toggleButton2 = wx.ToggleButton(self, label='Show Image', name='toggleButton2', pos=wx.Point(800, 295),
                                             size=wx.Size(90, 23), style=0)



        statbmp = wx.StaticBitmap(self.scrolledWindow1)
        self.statbmp = statbmp



        self.toggleButton2.Bind(wx.EVT_TOGGLEBUTTON, self.update_bitmap)
        self.statbmp.Bind(wx.EVT_MOTION, self.OnMotion)



    def OnMotion(self, event):
        pt = event.GetPositionTuple()  
       
        self.statusbar.SetStatusText(str(pt))
        event.Skip()



    def update_bitmap(self, event = None):
        """
        Bild holen und anzeigen
        """
        
        w, h = 3000, 2000 # hier sollte natürlich die korrekte Größe stehen
        bmp = wx.EmptyBitmap(w, h)
        dc = wx.MemoryDC(bmp)
        hdc = dc.GetHDC()
        
        
     
        tmpbmp = wx.Bitmap("spanish.jpg")
        dc.DrawBitmap(tmpbmp, 0, 0)
      
        # Bildaufbau blockieren
        self.scrolledWindow1.Freeze()
        
        # Bild zuweisen
        self.statbmp.SetBitmap(bmp)
        
        # ScrolledWindow einrichten
        self.scrolledWindow1.FitInside()
        self.scrolledWindow1.SetScrollbars(20, 20, w/20, h/20)
        
        self.statbmp.Refresh()
        
        # Bildaufbau wieder erlauben
        self.scrolledWindow1.Thaw()

def main(): 
    app = wx.PySimpleApp() 
    myframe = MyFrame() 
    #myframe.Center() 
    myframe.Show() 
    app.MainLoop()



if __name__ == "__main__": 
    main()


Danke!


Aleksandar

Verfasst: Montag 22. Januar 2007, 22:46
von Alexci
Ich habe mir die lupe irgendwie so vorgestellt, aber funktioniert nicht ganz... ist schwarz...

Code: Alles auswählen

# -*- coding: cp1250 -*-
import wx 
import wx.lib.scrolledpanel as scrolled
import wx.lib.buttons


class MyFrame(wx.Frame):
    def __init__(self, parent = None, id = -1, title = "", size = wx.Size(1000, 750)): 
        wx.Frame.__init__(self, parent, id, title= '', pos = wx.Point(0, 0), size = size)

        self.statusbar=self.CreateStatusBar()
        self.sashWindow1 = wx.SashWindow(self, name='sashWindow1', pos=wx.Point(820, 24), size=wx.Size(152, 128), style=wx.CLIP_CHILDREN | wx.SW_3D)
    
        self.scrolledWindow1 = wx.ScrolledWindow(self, name='scrolledWindow', pos=wx.Point(0, 24), size=wx.Size(780, 550), style=wx.HSCROLL | wx.VSCROLL)
        self.scrolledWindow1.SetBackgroundColour(wx.Colour(0, 90, 159))
        self.scrolledWindow1.SetScrollbars(1,1, 3000, 2000)
        self.scrolledWindow1.SetScrollRate(40,40)

        self.toggleButton2 = wx.ToggleButton(self, label='Show Image', name='toggleButton2', pos=wx.Point(800, 295), size=wx.Size(90, 23), style=0)

        statbmp = wx.StaticBitmap(self.scrolledWindow1)
        self.statbmp = statbmp
        self.setzoombmp = wx.StaticBitmap(self.sashWindow1)

        self.toggleButton2.Bind(wx.EVT_TOGGLEBUTTON, self.update_bitmap)
        self.statbmp.Bind(wx.EVT_MOTION, self.OnMotion)



    def OnMotion(self, event):
        pt = event.GetPositionTuple()  
       
        self.statusbar.SetStatusText(str(pt))
        event.Skip()

        zoombmp = wx.EmptyBitmap(152, 128)
        zoomdc = wx.MemoryDC(zoombmp)
        zoomdc.Blit(pt[0]-76, pt[1]-64, 152, 128, destination_dc1, 0, wx.COPY, useMask=False,)
        self.sashWindow1.Freeze()
        self.setzoombmp.SetBitmap(zoombmp)
        self.sashWindow1.FitInside()
        self.setzoombmp.Refresh()
        self.sashWindow1.Thaw()



    def update_bitmap(self, event = None):
        global destination_dc1
        
        w, h = 3000, 2000 # hier sollte natürlich die korrekte Größe stehen
        bmp = wx.EmptyBitmap(w, h)
        dc = wx.MemoryDC(bmp)
        hdc = dc.GetHDC()
        
     
        tmpbmp = wx.Bitmap("spanish.jpg")
        dc.DrawBitmap(tmpbmp, 0, 0)


        destination_bmp1 = wx.EmptyBitmap(w, h)
        destination_dc1 = wx.MemoryDC(destination_bmp1)
        destination_dc1.Blit(0, 0, w, h, dc, 0, 0, wx.COPY, useMask=False)


        self.scrolledWindow1.Freeze()
        self.statbmp.SetBitmap(bmp)
        self.scrolledWindow1.FitInside()
        self.scrolledWindow1.SetScrollbars(20, 20, w/20, h/20)
        self.statbmp.Refresh()
        self.scrolledWindow1.Thaw()


def main(): 
    app = wx.PySimpleApp() 
    myframe = MyFrame() 
    #myframe.Center() 
    myframe.Show() 
    app.MainLoop()


if __name__ == "__main__": 
    main()
Danke!

MfG,
Aleksandar

Verfasst: Dienstag 23. Januar 2007, 09:31
von gerold
Alexci hat geschrieben:Ich habe mir die lupe irgendwie so vorgestellt, aber funktioniert nicht ganz... ist schwarz...
Hi Aleksandar!

Du hast beim Kopieren die Koordinaten vertauscht. Zuerst die Zielkoordinaten und dann die Quellkoordinaten.

Code: Alles auswählen

        zoomdc.Blit(
            0, 0, 152, 128, destination_dc1, pt[0]-76, pt[1]-64, wx.COPY, useMask=False
        )
mfg
Gerold
:-)

Verfasst: Dienstag 23. Januar 2007, 20:06
von Alexci
WOW! Es geht! Danke!
:D

Aleksandar