Is there an equivalent of soft pen in GDI+? - graphics

I need to draw a soft wide outline for my GDI+ GraphicsPath.
Something like this:
A path edge is shown in red. I'd like to use a wide pen which is smooth. I also need an ability to control smoothness of the pen.
I tried to use a gradient brush with the pen but couldn't find a solution that works.
I can achieve the desired result by drawing an outline with a black solid pen and applying a Gaussian smoothing filter on top of the result image, but I want to avoid this because it's slow when I have to process the whole image which could be quite large.
Is there a way to draw a smooth path outline?

There is no standard way in GDI+ that provides this functionality so you will have to create it.
You could track the line segments and draw a fuzzy, filled circle along the segments. By drawling the fuzzy circle once to a bitmap it should be fairly easy and fast to blit it continuously. By blending it slowly over time to the canvas you can also create a very nice effect and it would allow the user to control the intensity and maybe the size of the circle.

Related

Clipping a circle with svg... or?

Currently I am using canvas to draw the gold circle, then snip off the areas half way to adjacent stars with globalCompositeOperation : destination-out, then paste the result into the main canvas.
I am contemplating changing to svg for this.
The closest method I have found is clip masks. I would have to create a set of clip-masks for each circle (star), this seems excessive if there were 2000 stars.
Another way would be to create polygons, but the math required to calculate the path may be beyond my capabilities.
So before I go down either of these routes, I would like to know if there is a better way or which of the above methods are recommended.

Cairo: Drawing with clip set gives fuzzy ornaments

I am programming a tool that has a custom canvas in it derived from Gtk::DrawingArea. The drawing does not happen directly on the DrawingArea. I have two Cairo::Surfaces. One surface is the Background (mostly an image) and the other surface is stuff that was drawn by the user.
When the user draws, I do not redraw the whole surface, I just set a clip on the Cairo context to only draw what is necessary. The Problem is, that when I have the clip set on the image background I can see a white frame around the clipped area. Is there a flag or a workaround, so the image would look good instead of having fuzzy frame ornaments around it?

libgdx - how to change the color of a pixel in a TiledMapTile?

I succeeded in retrieving the exact tile my player is on, at runtime when walking around the tiledmap. I'd like now to add some alpha marks on the terrain when passing over, and to do that I need to modify the color of some pixels of the tile.
I really don't know how to do it right now.. any hints?
thanks.
You probably want to draw decorations on top of the tiles, rather than modifying the tiles themselves. The tile images are shared across all cells using a tile, so if you modify the tile itself you would see the change everywhere it was used. Further, modifying the texture is a relatively expensive operation that you probably should try to avoid.
To draw on top the tiles, you might draw additional sprites, or use a custom shader.

In 3D graphics, why is antialiasing not more often achieved using textures?

Commonly, techniques such as supersampling or multisampling are used to produce high fidelity images.
I've been messing around on mobile devices with CSS3 3D lately and this trick does a fantastic job of obtaining high quality non-aliased edges on quads.
The way the trick works is that the texture for the quad gains two extra pixels in each dimension forming a transparent one-pixel-wide outline outside the border. Due to texture sampling interpolation, so long as the transformation does not put the camera too close to an edge the effect is not unlike a pre-filtered antialiased rendering approach.
What are the conceptual and technical limitations of taking this sort of approach to render a 3D model, for example?
I think I already have one point that precludes using this kind of trick in the general case. Whenever geometry is not rectangular it does nothing to reduce aliasing: The fact that the result with a transparent 1px outline border is smooth for HTML5 with CSS3 depends on those elements being rectangular so that they rasterize neatly into a pixel grid.
The trick you linked to doesn't seem to have to do with texture interpolation. The CSS added a border that is drawn as a line. The rasterizer in the browser is drawing polygons without antialiasing and is drawing lines with antialiasing.
To answer your question of why you wouldn't want to blend into transparency over a 1 pixel border is that transparency is very difficult to draw correctly and could lead to artifacts when polygons are not drawn from back to front. You either need to presort your polygons based on distance or have opaque polygons that you check occlusion of using a depth buffer and multisampling.

How to implement an eraser tool in a simple drawing app?

I have a prototype of a simple drawing application. When the user drags a finger across the screen, I record the points along the way and draw a series of lines between them. In other words, a drawing is a list of “paths” and each path is a list of points to connect. This is easy, it works and it’s efficient.
The problem is I’d like to implement an eraser tool. In a regular bitmap editor the eraser simply erases pixels, but in my drawing there are no pixels to erase – all pixels are created dynamically by stroking the paths. I could do a simple eraser by “drawing” using the background colour, overlaying the already painted paths. But I’d like to draw on a textured background, so that’s a no-go.
How would you do this? (Short of the obvious solution of representing the drawing as a bitmap where the eraser is simple.)
You can't implement an eraser in the traditional sense; what you describe with recording the paths and drawing them dynamically is vector graphics. The concept of an eraser comes from raster graphics (a bitmap, basically). With vector graphics, the user generally selects an item or an area of items to delete.
If you really wanted to do this, you'd basically have to do collision detection between all of the paths in your graphic and the rectangle (or whatever shape) of the eraser. When contact occurs, you'd have to cut the colliding graphic object on either side of the eraser by using the slope of the line(s) in contact with the eraser and the point of intersection.
You could probably find the intersections of your existing paths and the deleted area, split the existing paths up, and create new points at the intersections (which would become start/end points of the newly split paths).
I could do a simple eraser by
“drawing” using the background colour,
overlaying the already painted paths.
But I’d like to draw on a textured
background, so that’s a no-go.
Can't you do an "eraser by drawing" except you don't use a single color but the whole background as color. I mean, for a given path to erase, you take one by one each pixel and color it with the background color of the same pixel cordinates

Resources