[Chris]
> Here's the trick. When I first wrote ScaledBitmap, I was imaginig using
> it for small bitmaps, like icons, etc. So it's not at all smart -- when
> you zoom, it sclaes the entire image, then draws it, even though on ly a
> prortion may be visible.
>
> I"ve written a ScaledBitmap2, which does "the right thing", and only
> scales the portion of the image you need. It may be buggy if you orient
> it any way other than 'tl', or do anythign with a projection function,
> but give it a try:
>
> SBM = FloatCanvas.ScaledBitmap2(MyBitmapOrImage, (x,y), ...)
> Canvas.AddObject(SBM)
>
> and see how that works for you.

Thank you! The ScaledBitmap2() method worked perfectly. And thanks for
your work on FloatCanvas!!

I'm including a minimalistic app below, for future generations <wink>
It's a starting point anyway...

Bill

<code>
import os
import wx
from wx.lib.floatcanvas import NavCanvas, FloatCanvas

class MyFrame(wx.Frame):
    def __init__(self, *args, **kwargs):
        wx.Frame.__init__(self, *args, **kwargs)

        menuBar = wx.MenuBar()
        menu1 = wx.Menu()
        menu1.Append(101, "&Open", "Load an image")
        menu1.AppendSeparator()
        menu1.Append(102, "&Close", "Close the program")
        menuBar.Append(menu1, "&File")
        self.SetMenuBar(menuBar)

        self.sb = self.CreateStatusBar()

        nc = NavCanvas.NavCanvas(self, -1, Debug=0, BackgroundColor="GREY")
        self.Canvas = nc.Canvas

        # Set a min/max on scaling.
        self.Canvas.MinScale = 100
        self.Canvas.MaxScale = 5000

        self.SetPosition((0, 0))
        self.Show()

        self.Bind(wx.EVT_MENU, self.LoadImage, id=101)
        self.Bind(wx.EVT_MENU, self.CloseWindow, id=102)

    def LoadImage(self, evt):
        fileDlg = wx.FileDialog(self,
                                message = "Choose an image",
                                defaultDir = ".",
                                defaultFile = "",
                                # Add more file types here, but make sure
                                # to change the call to wx.Bitmap() below.
                                wildcard = "Supported files (*.tif) | *.tif",
                                style=wx.OPEN)

        if fileDlg.ShowModal() == wx.ID_OK:
            if hasattr(self, "bmp"):
                # Clear the Canvas before we load something else??
                self.Canvas.ClearAll()

            path = fileDlg.GetPath()
            head, tail = os.path.split(path)
            self.sb.SetStatusText("Loading: %s, please wait" % tail)

            # Change the call to wx.Bitmap() to use wx.BITMAP_TYPE_ANY
            # if you want to deal with images other than just TIF.
            self.bmp = wx.Bitmap(path, wx.BITMAP_TYPE_TIF)
            sb = FloatCanvas.ScaledBitmap2(self.bmp, (0,0), 1, Position="tl")

            self.Canvas.AddObject(sb)
            self.Canvas.ZoomToBB()
            self.sb.SetStatusText("Done loading: %s" % tail)

    def CloseWindow(self, evt):
        self.Destroy()

if __name__ == "__main__":
    app = wx.App(False)
    # A size of 1680 x 1020 fits my laptop nice ;) Change to suit.
    frame = MyFrame(None, title="A Simple Image Viewer", size=(1680, 1020))
    app.MainLoop()
_______________________________________________
FloatCanvas mailing list
[email protected]
http://paulmcnett.com/cgi-bin/mailman/listinfo/floatcanvas

Reply via email to