(Before this gets marked as a duplicate, I'd like to say that I've tried the answers on other posts, but they don't seem to work for my specific issue.)
I'm creating a sort of "map game", where there's a map split into multiple areas. Currently, this is what I have:
It works, but it's not pretty. I want to make the buttons (currently they're the Rectangle control, but I can change that easily) the right shape.
I tried making a path in Inkscape, which gave me this SVG path:
m 283.60033,267.22114 11.61675,32.57742 14.14214,-8.33376 10.35406,-1.01015 11.61676,-5.3033 10.6066,-5.05077 0,-16.66751 -34.85027,-3.78808 -8.08122,2.77792 -14.64721,0.75762 z
However, when I tried to make a Button (and later Polygon) use the path, it didn't work and instead made a completely different shape.
The Buttons need to have a background color that can change during runtime, so a PictureBox won't work.
Is there a reason why the Path didn't work? Or maybe there is a much easier method?
EDIT: Here is the code I used for the Polygon
<Polygon Fill="Blue" Points="283.60033,267.22114 11.61675,32.57742 14.14214,-8.33376 10.35406,-1.01015 11.61676,-5.3033 10.6066,-5.05077 0,-16.66751 -34.85027,-3.78808 -8.08122,2.77792 -14.64721,0.75762" Margin="248,102,956,22" RenderTransformOrigin="0.5,0.5" Grid.ColumnSpan="2"/>
And here is the result, which is the same shape I got when I tried changing the shape of a Button (unfortunately I deleted the code for that):
Here is what it should look like (path drawn in Inkscape):
I figured it out and it was actually pretty easy! I actually didn't need Inkscape at all.
I imported the map image into Blend, and I traced the area with the Pen tool and made it into a Path, which I copied back into Visual Studio.
Example:
Are you sure you didn't get mixed up with which part you picked out the xaml inkscape produced?
Because that's roughly the top right part of the iberian peninsular. Like your drawn map. Roughly anyhow. That's just a polygon - with hard edges. Meaning however you produced it, you didn't trace the curvy/rough edges of what you're showing us.
Also.
If you look at the data that's in it.
See where it starts?
m 283.60033,267.22114
Those are x,y co-ordinates.
268px left, 267px down
From the top left corner of whatever container you put it in.
Is that going to work for you?
Related
I have no experience with images. I have to detect simple object in static image. For example I have image like:
I want to detect edges and remove background. Just to compare them.
Something like this.
Do u have any solutions of this problem? Images have often white backgrounds.
I've just thought about detect edges, and take everything what they contains.
To segment out the shoe-
Anadptive Threshold to remove the smooth changing background.
Sobelx, which removes the apparent background line, which i assume is
common for images of this setup.
dilate, closing operation to separate out the shoe.
Find contours, bounding box etc as per your choice.
Do an additional threshold if you want to remove the shadow at the bottom.
I have an application with a Microsoft.Maps.MapControl.WPF map, and a few layers added with mapView.Children.Add(layer).
Each of those layers has different types of overlays on it, which are images added with layer.Children.AddChild(image, locationRect).
I want to be able to move, resize and rotate those objects from code (not from xaml which knows nothing about them), but I don't seem to be able to do the first two (rotation being quite simple).
After trial and error and finding some non Microsoft documentation I see that MapLayer.GetPositionRectangle(UIElement) returns the correct location of the object, so it would seem logical that MapLayer.SetPositionRectangle() should set it, but it doesn't and I can't find any examples of anything on the web that programatically moves an object to a new Lat/long.
Is there a way of moving a geographical object on the map, or do I have to either remove it and add it in the right place, or just move it on the canvas in X/Y coords that I have worked out from the lat/long, both of which seem wrong somehow, but this is my first WPF application (normally use forms) and maybe this is the way it is done?
The Windows-universal-samples that exist on Microsoft github page can help you. There is an example of MapControl where you can get some ideas.
This sample demonstrates how to use the universal map control (MapControl) in a UWP app.
MapControl Basics: adjusting the ZoomLevel, Heading, DesiredPtich, and map stype
Adding points of interest on the map: PushPins, images, and shapes
Adding XAML overlays on the map
Showing 3D locations in MapControl
Showing Streetside experience within MapControl
Launching Maps using URI Schemes
Url: https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/MapControl
After this example, if there is more question, post here to solve it.
I think, the best way is getting an model for this XAML, where you can update this properties.
What you can do is apply standard transitions to your image through code. you can use the MapLayer.SetPosition to link it to a location on the map. You may want to use an position origin/offset or a margin to align a specific point of the image with the location.
https://msdn.microsoft.com/en-us/library/microsoft.maps.mapcontrol.wpf.maplayer.setposition.aspx
https://msdn.microsoft.com/en-us/library/microsoft.maps.mapcontrol.wpf.maplayer.setpositionorigin.aspx
https://msdn.microsoft.com/en-us/library/microsoft.maps.mapcontrol.wpf.positionorigin.aspx
https://msdn.microsoft.com/en-us/library/microsoft.maps.mapcontrol.wpf.maplayer.setpositionoffset.aspx
Nothing much to it, just a general question. I've searched for ages on the web but I can't find anything that answers my question.
is this possible? I want to parent one picturebox to another (which is below the one I want to parent) to allow the transparency to work properly for the top picturebox. But the picturebox's location changes off to somewhere off screen which is what I don't want.
If there is nothing like that, then are there any suggestions?
Currently I'm working with very small pictureboxes and I've tried everything to get the top image to be in the same place, including things like this code:
Btn_Close2.Location = New Point(Btn_Close2.Location.X - Btn_Close.Left, Btn_Close2.Location.Y - Btn_Close.Top)
But the top picturebox just wonder's off somewhere.
I would have thought this was a common desire, but I'll be damned if I can find this.
I simply want to Animate an image by swapping two images back and forth. I tried StoryBoard, but apparently you can't change the source in a storyboard. The only answer I can come up with is a Timer, which I don't think is the best way.
Edit: How do I animate image content in WPF? Came up in the "Similiar Questions" window. And while this will do what I want, it is "hackish" as the OP of it says, and it only swaps two images, what if I wanted a whole sequence of 10 or 20 or 100.
I found another post here on SO whose answer sounds like it could solve your problem: Change an image during animation using storyboard
The problem with this approach is that it also doesn't satify your request for supporting an arbitrary number of images.
I was going to propose a different method that involves databinding the Image Source to the image path, and then in code behind simply changing the path, but I haven't gotten it to work yet.
Here's an article that seems to have an elegant way to handle your requirements: http://www.codeproject.com/Articles/364529/Animation-using-Storyboards-in-WPF
Hopefully that will work for you.
I'm writing a paint application. User must be able to move with all objects after it's painted or edited. I have a brush and erase tool, so user can erase all or any part of object painted with brush. So I made an object DrawBrush that holds a System.Drawing.Region made from GraphicsPath.
But I don't know how to size it. I need to change size in every direction separately on mouse move (for example only to left)
can someone help me?
I'm able to do anything with this object (moving), but no sizing...
A region is like a fence - it simply marks out the boundary of an area. It does not "contain" any graphics, so resizing a region will have no direct/visible effect.
If you wish to be able to move or resize portions of a bitmap image within your editor, you will need to copy a piece of your main image (as specified by your region) into a temporary Bitmap. Then you can draw the tempoary bitmap back to your main image (in a different location and/or at a different size).
If you wish to be able to draw multiple objects in your painting program, and then edit them (move them around and resize them) independently later, then you will need to store each of them in a separate bitmap object and composite them together to display the final image on screen or save it to a flat bitmap format. If you don't keep all the shapes separately like this, you will lose too much information and you won't be able to edit them later.
Before you try to work out write the code to do this, you may need to think about the design of your editor - what does it need to do, and how will you achieve it? How is your "document" going to be described? (A single bitmap? many small bitmaps that are drawn at different locations? Vector paths?). If you write code before you understand how you will represent the document, you're likely to paint yourself into a corner (sorry about the pun) and get totally stuck.