On Tue, Mar 18, 2014 at 4:12 AM, Nouvelle Collection <
[email protected]> wrote:
> A small question : sometimes I want to get the (x,y) hitcoords when
> clicking on an 309x34 pixels image, and I would like x to be an integer in
> [0, 308], but when self.canvas.ZoomToBB() has been used, sometimes the
> (x,y) coordinates are a bit "off" of some pixels.
>
> For example, when using x = event.HitCoords[0] -
> event.BoundingBox[0,0], the range I get for x is [-1.2598, 302.24277] =>
> how to get [0,308] instead ?
>
> Is there a parameter somewhere for HitCoords accuracy ? (high, medium,
> etc.)
>
No -- it's limited by pixel accuracy for the mouse click, and floating
point accuracy for the scaling calculation. So it depends on the zoom
level.
1) you'll want to round.
2) It depends on the zoom level -- if you have 308 pixel wide image, but
are showing it so that 4 pixels in the image are only one pixel big on the
screen, you can only get so close.
When I try this with the ScaledBitmap2 demo, it seems to work as well as
I"d expect.
The scale depends on two thing: how the ScaledImage is originally sclaed to
World Coords:
img = FloatCanvas.ScaledBitmap2( image,
(0,0),
Height=image.GetHeight(),
Position = 'tl',
Quality='high'
)
This is setting the Height in world coords the same as the image height in
pixels -- so you should get a 1:1 scaling of pixels to works coords
print Canvas.Scale
will tell you how WorldCoords are being scaled to the final drawn image:
print "The Scale is set to:", self.Canvas.Scale
For me, if it's close to 1.0, it works pretty well, much under one, and
you're seeing the limitations of pixel resolution.
However, I did find a big (mis-feature?): The ScaledBitmaps were getting
the HitLineWidth from the default DrawObject. But for those, you really
don't want a line width for the hit-test bitmap. It was set to 3 pixels, so
was letting the image be "hit" an extra 1-2 pixels outside the actual image.
Fixed in SVN.
-Chris
>
> Best regards, Jo
> ____
>
> import wx
> from wx.lib.floatcanvas import FloatCanvas
>
> class TestFrame(wx.Frame):
> def __init__(self, *args, **kwargs):
> wx.Frame.__init__(self, *args, **kwargs)
> self.canvas =FloatCanvas.FloatCanvas(self, BackgroundColor = "DARK
> SLATE BLUE")
> MainSizer = wx.BoxSizer(wx.VERTICAL)
> MainSizer.Add(self.canvas, 4, wx.EXPAND)
> self.SetSizer(MainSizer)
> img = wx.Image('mypng(309x34).png')
> A = self.canvas.AddScaledBitmap(img, (0,0),
> Height=img.GetHeight(), Position = 'tl')
> A.Bind(FloatCanvas.EVT_FC_MOTION, self.OnMotion)
> wx.CallAfter(self.canvas.ZoomToBB)
>
> def OnMotion(self, event):
> x, y = event.HitCoords[0] - event.BoundingBox[0,0],
> event.BoundingBox[1,1] - event.HitCoords[1]
> print x, y # the max range I can get for x is [-1.2598,
> 302.24277] => how to get [0,308] instead ?
>
> app = wx.App(0)
> frame = TestFrame(None, title="Image hitcoords", size=(300,200))
> frame.Show(True)
> app.MainLoop()
>
>
>
>
>
> _______________________________________________
> FloatCanvas mailing list
> [email protected]
> http://mailman.paulmcnett.com/cgi-bin/mailman/listinfo/floatcanvas
>
>
--
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