Filling a pie slice of a rectangle - c#

I want to fill a slice of a rectangle based upon a value which doesn't correlate to the degree of the rectangle that needs to be filled.
Say this square below, I would want the area that is light gray to get bigger and bigger (Like a slice of a pie getting bigger) until the entire square is light gray.
How would I go about doing this using System.Drawing? I tried using FillPie but it doesn't fill the square corners

Set the Graphics.Clip property to a region that represents the rectangle, then FillPie with an oversized radius such that the "pie" completely covers the rectangle.

Related

Unity3D- Is it possible to draw a circle / ellipse based on two vertices using a linerenderer?

I would like to ask if it is possible to generate and draw a circle or ellipse using a linerenderer based on two points in the scene. Specifically, these are the vertices of the mesh. For example, I would like to draw a circle / ellipse around the neck of a given humanoid.
I need something like this:
I need this circle to enlarge and shrink based on the properties of the blendshapes. If I widen the neck with blendshape, I need this circle to enlarge as well. I can draw this circle by finding the id of all the vertices around the neck and entering these vertices into the LineRenderer. But it's a very impractical way that I don't want to use. So I would like to ask if it is possible to draw such a circle that would be connected only to two points and not to all / many.
I will be very grateful for any advice.
EDIT:
I was hoping that it would be enough to connect 4 vertices in the worldspace using LineRenderer, where I would get a drawn square. And I was hoping that some rounding would be used on the edges of this square to create an ellipse or circle. For a better idea, I also added a picture to describe what I thought would be enough to use.

Is there any way to make Graphics.TranslateTransform() permanent?

I am using the Graphics class to draw a legend followed by a heat map.
As I draw the heat map, I am calling TranslateTransform() to work on a specific part then ResetTransform() before moving onto the next part.
After I draw the legend, I'd like to permanently shift my graphics matrix by the legend's height such that ResetTransform() always returns to below the legend. Currently, every time I ResetTransform(), I have to Restore() to my base origin (below the legend).

How to reach a circle and detect its color?

I have some circles located in an image, I could find the location for each circle (diameter and origin or centre), so first of all how could I check all pixels inside that circle (I'm thinking of for loop). second how could I ask if pixel color in nearly gray?
At first I thought of asking if Red, Green and Blue values are higher than 125 But that doesn't work. For example: (200,130,170) is for sure not a gray color!
If you want to check whether a point is within a circle, use pythagoras..
Math.sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2))
..to work out how far the point (x1,y1) is from the center (x2,y2) of the circle. If the value you calculate is less than the radius of the circle, the point is in the circle. This can be optimised slightly by removing the sqrt, and testing if the result is less than the square of the radius
Anything is nearly gray if the RGB are nearly the same. 64,64,64 = dark grey, 72,64,64 = slightly red looking dark grey. You'll have to define what "nearly" means

Silverlight Transforms Images C#

I have an image on which I may use a ScaleTransform to increase the image size by 25%. I also have a rectangle which sits on top of the image highlighting a particular area. When I scale the image I want the rectangle to scale as well and highlight the same area as before. Scaling the rectangle itself isn't the issue, it's getting the rectangle into the correct position so that it highlights the same area. How do I do this? Is there a mathematical formula of some description that can be used to calculate its correct position?
Apply the same scaling factor to the X and Y offsets of the rectangle.

Draw Points onto canvas using an offset?

I have an array of Point variables. When drawn using Graphics.DrawLine, they create the expected image. My problem is that 0,0 is actually the center of the image (not the top left of my canvas as expected. My X and Y coordinates in the Points can contain negative numbers.
When I try to draw this to my Image, of course I get 1/4 of the total image as the remainder is drawn outside the bounds of my canvas. How do I center this drawing correctly onto my canvas?
I know the dimensions of the image I want to draw. I know where 0,0 is (width / 2, height / 2).
I suppose I can translate each and every single Point, but that seems like the hard way to do this.
TranslateTransform() can map coordinates for you if you setup a transformation during your drawing handlers.
Graphics.TranslateTransform # MSDN
Or, map your coordinates by adding half the width and half the height of the desired viewing area to each coordinate.
Also, you may need to scale your coordinates. You may use Graphics.ScaleTransform to do this.
Graphics.ScaleTransform # MSDN
If you don't wish to use this, then you should divide X coordinates by the percent amount you wish to stretch the width, and divide Y coordinates by the percent amount you wish to stretch the height. This gives us 1 for 100%, 1.2 for 120%, 0.8 for 80%, etc.
Welcome to the Windows' version of the Cartessian Plane. Your last statement is correct. You do have to offset each and every point. The only real help you can give yourself is to make the offset logic a separate method to clean up your main drawing code.
When creating the array, add an offset to each x value equal to half of the width and an offset to y equal to half of the height. That way when the points are drawn, they're in the expected position.

Categories