Outline object magic lasso brush2/20/2023 ![]() ![]() The code below is what I've used to draw the region outline. I'm including the SafeHandle wrapper classes and the code I've used to make this work below, for the sake of completeness. Thanks to Peter Duniho's answer, I managed to solve this problem. I've already tried creating new points from each of the rectangles by calculating the most adjacent points on both the Left and Right points of each rectangle, and rendering those as individual rectangles, but to no avail.Īny help would be greatly appreciated, as I'm really at a loss here. Something that's trivial for humans to do, but I can not figure out for the life of me how to instruct a computer to do this for me. I'm looking for a way to connect the dots in order to create an outline of the rectangles in my region. G.DrawRectangle(p, pointPair.X, pointPair.Y, 1, 1) To do this, I tried the following code: var pointPair = new I figured I'd only draw the left and right edges of each of the rectangles on the screen, so I'd end up with a bunch of points on the screen which outline the image for me. Because of this, I can't view the actual image anymore, and my wand tool now makes the image useless. However, as I'm drawing rectangles, I also end up with horizontal lines, which weren't a part of the original magic wand selection. The outline here is correct - that's exactly what I originally marked with my magic wand tool. The above code results in the following being rendered in my picture control: New Rectangle(new Point((int)r.Location.X, (int)r.Location.Y), Var niceBrush = new SolidBrush(Color.Orange) Var b = new SolidBrush(picBox.BackColor) Var alternatePen = new Pen(Color.BlueViolet, 1f) I have isolated the entire drawing process to a WinForms application, and I'm using the following code to draw this collection of rectangles on an image control: using (var g = Graphics.FromImage(picBox.Image)) ![]() This way I end up with a collection of rectangles that I use to draw and reconstruct the region. RectangleF rectangles = region.GetRegionScans(new Matrix()) I then create a Region and pass the above RegionData object in the constructor and call GetRegionScans to obtain the rectangle objects which comprise the region: var region = new Region(regionData) (RegionData)FormatterServices.GetUninitializedObject(typeof(RegionData)) The RegionData's only member is a "data" byte array, which we set right after. Constructors don't run, but in this very specific case - they don't have to. I store the byte kept in the RegionData.Data property in a base64 string, so I can retrieve the RegionData later through a somewhat unconventional method: // This "instantiates" a RegionData object by simply initiating an object and setting the object type pointer to the specified type. Returns a RegionData that represents the information that describes this Region. As the specification specifies, this method: To obtain the data for storage, I'm utilizing the GetRegionData method. As part of a project I'm working on I have to store and restore magic wand regions from an image. ![]()
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |