Skip to main content
deleted 22 characters in body
Source Link
M.R.
  • 31.8k
  • 8
  • 96
  • 289

I have dynamic graphics over an image but they won't line up, what am I doing wrong?

img = ExampleData[ExampleData["TestImage"][[1]]];
d = ImageDimensions@img;
pt1=d/4;pt2={d[[1]]3/4,d[[2]]1/4};pt3=3d/4;pt4={d[[1]]1/4,d[[2]]3/4};

MultiContourPolygon[polys_List] := Module[{contours = Append[#, First[#]]&/@polys}, 
    {Polygon@Join[Join@@contours,Reverse[First/@contours]],Line[contours]}
]

LocatorPane[
    Dynamic[{pt1,pt2,pt3,pt4}],
    Overlay[{Image[img,ImageSize->400]img, 
        Graphics[{Orange, Opacity[.4], 
            Dynamic @ MultiContourPolygon[{{pt1,pt2,pt3,pt4}, {{0,0}, {d[[1]],0},d,{0,d[[2]]}}}]},
            ImagePadding -> 0, ImageMargins ->0> 0, ImageSize ->400> d
        ]
        }, Alignment -> {Left, LeftBottom}, ImageSize -> 400d
    ]
]

enter image description here

I have dynamic graphics over an image but they won't line up, what am I doing wrong?

img = ExampleData[ExampleData["TestImage"][[1]]];
d = ImageDimensions@img;
pt1=d/4;pt2={d[[1]]3/4,d[[2]]1/4};pt3=3d/4;pt4={d[[1]]1/4,d[[2]]3/4};

MultiContourPolygon[polys_List] := Module[{contours = Append[#, First[#]]&/@polys}, 
    {Polygon@Join[Join@@contours,Reverse[First/@contours]],Line[contours]}
]

LocatorPane[
    Dynamic[{pt1,pt2,pt3,pt4}],
    Overlay[{Image[img,ImageSize->400], 
        Graphics[{Orange, Opacity[.4], 
            Dynamic @ MultiContourPolygon[{{pt1,pt2,pt3,pt4}, {{0,0}, {d[[1]],0},d,{0,d[[2]]}}}]},
            ImagePadding -> 0, ImageMargins->0, ImageSize->400
        ]
        }, Alignment -> {Left, Left}, ImageSize -> 400
    ]
]

enter image description here

I have dynamic graphics over an image but they won't line up, what am I doing wrong?

img = ExampleData[ExampleData["TestImage"][[1]]];
d = ImageDimensions@img;
pt1=d/4;pt2={d[[1]]3/4,d[[2]]1/4};pt3=3d/4;pt4={d[[1]]1/4,d[[2]]3/4};

MultiContourPolygon[polys_List] := Module[{contours = Append[#, First[#]]&/@polys}, 
    {Polygon@Join[Join@@contours,Reverse[First/@contours]],Line[contours]}
]

LocatorPane[
    Dynamic[{pt1,pt2,pt3,pt4}],
    Overlay[{img,
        Graphics[{Orange, Opacity[.4], 
            Dynamic @ MultiContourPolygon[{{pt1,pt2,pt3,pt4}, {{0,0}, {d[[1]],0},d,{0,d[[2]]}}}]},
            ImagePadding -> 0, ImageMargins -> 0, ImageSize -> d
        ]
        }, Alignment -> {Left,Bottom}, ImageSize -> d
    ]
]

enter image description here

Source Link
M.R.
  • 31.8k
  • 8
  • 96
  • 289

How to align dynamic graphics and an image within an Overlay?

I have dynamic graphics over an image but they won't line up, what am I doing wrong?

img = ExampleData[ExampleData["TestImage"][[1]]];
d = ImageDimensions@img;
pt1=d/4;pt2={d[[1]]3/4,d[[2]]1/4};pt3=3d/4;pt4={d[[1]]1/4,d[[2]]3/4};

MultiContourPolygon[polys_List] := Module[{contours = Append[#, First[#]]&/@polys}, 
    {Polygon@Join[Join@@contours,Reverse[First/@contours]],Line[contours]}
]

LocatorPane[
    Dynamic[{pt1,pt2,pt3,pt4}],
    Overlay[{Image[img,ImageSize->400], 
        Graphics[{Orange, Opacity[.4], 
            Dynamic @ MultiContourPolygon[{{pt1,pt2,pt3,pt4}, {{0,0}, {d[[1]],0},d,{0,d[[2]]}}}]},
            ImagePadding -> 0, ImageMargins->0, ImageSize->400
        ]
        }, Alignment -> {Left, Left}, ImageSize -> 400
    ]
]

enter image description here