I'm trying to figure out how to stop LinearGradientBrush to repeat along with shape I'm drawing. So, for example I created gradient with height equal to 50, but next I draw rectangle with height equal to 150. In that case gradient will repeat itself three times. But I'd like to draw only first gradient and draw nothing for the rest of rectangle.
Seems GradientBrush in WPF supports SpreadMethod(http://msdn.microsoft.com/en-us/library/system.windows.media.gradientbrush.spreadmethod.aspx) for this purpose, but does something exists for WinForms as well?
Paul, I think the easiest way may be to create your fill the same way, but only draw using a rect of 50 pixels. If you need to fill the other 100 pixels with a specific color, then do a solid fill with that color first.
Alternatively, you can try to set a blend in your gradient fill (LinearGradientbrush::SetBlend), but that seems like a lot of effort to achieve the same effect.
Related
Given a sprite sheet with a plain background like this:
I want to take each individual image off this background and create a file for it. I've looked around and had trouble finding information on how to do this - I cant help but feel there is some simple method. Does anyone have any pointers?
Caveat: Not all sprite sheets are the same format/layout, e.g. this one:
It's laid out slightly differently, and this one is even weirder.
So some challenges:
The background of the sprite sheet varies in colour.
Sprites in the sprite sheet vary in size, and that size cannot be specified ahead of time.
Method must generalize (reasonably well) to thousands of sprite sheets.
Appreciate any help.
Taken from: https://www.reddit.com/r/computervision/comments/ej3wgr/extracting_images_from_a_simpleplain_background/
by /u/tzatza
1) detect background color (sample appropriately, say from image edges), one option is with votes in a hashtable (key = r+"-"+g+"-"+b)
2) setup a mask, set all the background pixels to zero in mask within certain color distance of background, set all other mask pixels to 1.
3) optionally: erode the mask once (or twice), then dilate back to remove useless lines.
4) you now have a mask of 0 vs 1, do flood fill on each grouping of 1s to determine the extent of each sprite. Set mask pixels to "2" as you do the flood fill to indicate visited.
5) as you flood fill, track each sprite's min/max x/y and at the end of the flood fill, you have the extents (and a mask) which can be used to crop/store.
I know this goes against Stackoverlow principles of putting in the entire answer, but may I suggest you search for the "Blue Screen Matting" paper by Alvy Ray Smith & Jim Blinn. There's a copy available here.
They have been in the graphics industry for decades and so "know their stuff".
Given a number of points on a 2d surface and radiuses for these points I can easily paint circles for them. What I need is an algorithm that only paints the envelope (right word for what I am looking for?) or outer bound of these combined circles. Additionally a second set of circles can 'encroach' on these circles, resulting in a kind of 'border'.
Image of what I am looking for
A quick way to draw the outline of the union of the disks is to
fill all disks in yellow, then
fill all disks in white with a smaller radius.
This can be adapted to the "encroached" circles, provided you only fill the remaining portions of the disks. Unfortunately, in a general setting finding the remaining portions can be an uneasy geometric problem.
There is an alternative approach which can work in all cases:
fill an image with zeroes, then for all disks fill every pixel with the value of the distance to the circumference (maximum at the center), but only keep the highest value so far.
while you do this, fill a second image with the color of the disk that achieved that highest value. (Initialize the image with the background color.)
At the end of this process, the first image will represent a "terrain" made of intersecting cones; and for every point of the terrain, you will know the color.
finally, color the pixels that have a height smaller than the desired stroke width, using the color map.
You can do the drawing in two steps.
1) Draw the outline using the following method: For each point, draw a circle using your favorite circle-drawing method, but before drawing a pixel, ensure that it is not contained inside any other circle. Do this for every point and you will get your outline.
2) Draw the borders between different sets using the following method: For each pair of points from different sets, calculate the two intersection points of the circles. If there is an intersection, the border can be drawn as a segment joining these two points. However, you have to make two lines, one for circle A, and another for circle B. To draw the line for circle A, slightly offset the segment towards point A. Then, use your favorite line-drawing method, but before drawing a pixel, ensure that it is closer to point A that any other point of the opposite set. After drawing the line, repeat the process for circle B. Note that both segment are not guaranteed to be the same length since the asymmetry of the points of the different sets. It will, however, always form a closed shape when all outlines and borders are drawn.
I have a 2d grid where pixel centers are at the intersection of two half-grid lines, as shown below.
I also have a shape that is drawn on this grid. In my case the shape is a glyph, and is described by segments. Each segment has a start point, end point and a number of off-curve points. These segments can be quadratic curves or lines. What's important is that I can know the points and functions that make up the outline of the shape.
The rule for deciding which pixels should be turned on is simple: if the center of the pixel falls within the shape outline, turn that pixel on. The following image shows an example of applying this rule.
Now the problem I'm facing has to do with anti aliasing. What I'd like to do is to calculate what percentage of the area of a given pixel falls within the outline. As an example, in the image above, I've drawn a red square around a pixel that would be about 15% inside the shape.
The purpose of this would be so that I can then turn that pixel on only by 15% and thus get some cleaner edges for the final raster image.
While I was able to find algorithms for determining if a given point falls within a polygon (ray casting), I wasn't able to find anything about this type of problem.
Can someone can point me toward some algorithms to achieve this? Also let me know if I'm going about this problem in the wrong way!
This sounds like an X, Y problem.
You are asking for a way to calculate the perecentage of pixel coverage, but based on your question, it sounds that what you want to do is anti alias a polygon.
If you are working only with single color 2D shapes (i.e red, blue, magenta... squares, lines, curves...) A very simple solution is to create your image and blur the result afterwards.
This will automatically give you a smooth outline and is simple to implement in many languages.
I am trying to give some border to my cross text which around 45 degree in excel but issue is that whenever i apply border to cross text the border also get apply at 45 degree.
I am looking for a straight rectangle border which contains cross text in it in excel.
Please help me to do that
I dont think you can find a way around that, but you could improvise;
try removing all the borders on that particular cell then sort of draw a rectangle (Or similar shape) and set its fill to nothing so it can give this impression of a "straight border" and this will look good, if you format it well that is, on printed paper.
Or you can draw a textbox on top of the cell (with the same size) and remove any color fill
If there's an option of locking its position, it would be useful too
I want to draw something like a pie chart segment filled with a certain color.
I know we can draw a circle using the Me.Circle function in a PictureBox to get a filled circle. However, when you add the start and end the circle becomes just a single lined arc.
Can anyone offer me a solution?
It is possible.
Check http://www.wiley.com/college/mckeown/0471418625/ppt/ch11.ppt