Thanks for your answer Chris.

Here is a code example and two PNG image samples.

[ If you replace line 18 by line 19 (ie wx.CallLater) then it seems that it
works. ]

Thanks in advance, Jo


2014-02-03 Chris Barker <[email protected]>:

> On Mon, Feb 3, 2014 at 1:15 PM, Nouvelle Collection <
> [email protected]> wrote:
>
>> self.Canvas.AddScaledBitmap(image, (0,0), Height=image.GetHeight(),
>> Position = 'tl')
>>
>>
> hmm -- this will create a ScaledBitmap with "world" height of 100 pixels.
>
>
>
>> When I use a PNG of size (x,y) with x <= 100 or y <=100, I have a crash
>> with the following traceback when I do ZoomToBB()   :
>>
>> Traceback (most recent call last):
>>>>>   File "D:\Documents\test.py", line 471, in Draw
>>>>>     self.Canvas.ZoomToBB()
>>>>>   File "D:\Documents\floatcanvas\FloatCanvas.py", line 3035, in
>>>>> ZoomToBB
>>>>>     self.SetToNewScale(DrawFlag=DrawFlag)
>>>>>   File "D:\Documents\floatcanvas\FloatCanvas.py", line 3048, in
>>>>> SetToNewScale
>>>>>     self.Draw()
>>>>>   File "D:\Documents\floatcanvas\FloatCanvas.py", line 2846, in Draw
>>>>>     self._DrawObjects(dc, self._DrawList, ScreenDC, self.ViewPortBB,
>>>>> HTdc)
>>>>>   File "D:\Documents\floatcanvas\FloatCanvas.py", line 3186, in
>>>>> _DrawObjects
>>>>>     Object._Draw(dc, WorldToPixel, ScaleWorldToPixel, HTdc)
>>>>>   File "D:\Documents\floatcanvas\FloatCanvas.py", line 1968, in _Draw
>>>>>     Img = self.Image.Scale(W, H)
>>>>>   File
>>>>> "C:\ProgramData\Anaconda\lib\site-packages\wx-3.0-msw\wx\_core.py", line
>>>>> 2916, in Scale
>>>>>     return _core_.Image_Scale(*args, **kwargs)
>>>>> wx._core.PyAssertionError: C++ assertion "(width > 0) && (height > 0)"
>>>>> failed at ..\..\src\common\image.cpp(433) in wxImage::Scale(): invalid new
>>>>> image size
>>>>>
>>>>
>> Do you have any idea for the reason of this error ?
>>
>
> One idea  -- what else is on the canvas -- if everything else if big
> enough (or far enough away) so that zooming to the bounding box would make
> the ScaledBitmap less than 1 pixel in size, then it may be trying to scale
> to a 0-pixel image, which would trigger this. But I"m surprised that I
> didn't already have a check for that.
>
> That should be near here:
>
>   File "D:\Documents\floatcanvas\FloatCanvas.py", line 1968, in _Draw
>     Img = self.Image.Scale(W, H)
>
> look and see if there is check for size-zero for W or H  -- if not then
> there should be, and it can just skip the rest of the _draw method
> -- nothing to draw.
>
>
>
>> Note : if I resize (with MSPaint for example) the PNG to 101x101 pixels,
>> there is no error anymore..
>>
>
> Also,  it seems odd that it would happen at exactly 100 pixels -- quite  a
> round number.
>
> If you post a small sample that breaks and the png that breaks it -- I'll
> take a look.
>
> -Chris
>
>
>
>
>
> --
>
> Christopher Barker, Ph.D.
> Oceanographer
>
> Emergency Response Division
> NOAA/NOS/OR&R            (206) 526-6959   voice
> 7600 Sand Point Way NE   (206) 526-6329   fax
> Seattle, WA  98115       (206) 526-6317   main reception
>
> [email protected]
>
> _______________________________________________
> FloatCanvas mailing list
> [email protected]
> http://mailman.paulmcnett.com/cgi-bin/mailman/listinfo/floatcanvas
>
>

<<attachment: bmp1.png>>

<<attachment: bmp2.png>>

import wx
from wx.lib.floatcanvas import FloatCanvas

class MyPanel(wx.Panel):
    def __init__(self, parent):
        super(MyPanel, self).__init__(parent)
        self.SetBackgroundColour(wx.WHITE)
        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.SetSizer(self.sizer)
        self.Canvas = FloatCanvas.FloatCanvas(self, BackgroundColor = "LIGHT GREY")
        self.Canvas.MaxScale = 2        
        self.sizer.Add(self.Canvas, -1, flag=wx.EXPAND)
        bmp1 = wx.BitmapFromImage(wx.Image('bmp1.png', wx.BITMAP_TYPE_PNG))
        bmp2 = wx.BitmapFromImage(wx.Image('bmp2.png', wx.BITMAP_TYPE_PNG))            
        img1 = self.Canvas.AddScaledBitmap(bmp1, (0, 0), Height = bmp1.GetHeight(), Position = 'tl')
        img2 = self.Canvas.AddScaledBitmap(bmp2, (100, -100), Height = bmp2.GetHeight(), Position = 'tl')
        
        self.Canvas.ZoomToBB()
        #wx.CallLater(1, self.Canvas.ZoomToBB)
     
class DemoApp(wx.App):
        def __init__(self, *args, **kwargs):
            wx.App.__init__(self, *args, **kwargs)
            frame = wx.Frame(None)
            MyPanel (frame)
            frame.Show()

app = DemoApp(False)
app.MainLoop()
_______________________________________________
FloatCanvas mailing list
[email protected]
http://mailman.paulmcnett.com/cgi-bin/mailman/listinfo/floatcanvas

Reply via email to