I build an application which part is also drawing into video frames. For this I am using Graphics library from System.Drawing. Drawing is working fine and is already implemented. But I also need to be able to draw straight lines with for example this kind of curvy pattern:
.
Could somebody help me how this could be achievable?
Related
I need to render shapes to a Texture2D (lines, rect, roundrect, filled and line polygons). I can't find a proper solution for this. I found one very basic library for drawing but that only can draw line and fill rect. I rather not want to write my own rendering library in 2021 or hacking SkiaSharp in unity.
It would be nice to find any c# graphics library what is just rendering to an rgb array, but I can't find any so far.
What would be the best solution for this?
I currently have a WinForms C# application. I have a .txt file with GPS coordinates of some points (borders of buildings, roads etc.), and using Graphics.FillPolygon method in System.Drawing I am drawing these on a Panel. However, I got an idea that for what I am trying to do (it basically is a 2D game), a Unity 2D project would be more suitable and easy to use (mainly because of easier view handling using the cameras). However, I don't know how to do this drawing in it. I just need to somehow get these coordinates drawn in Unity, but I don't know how to do it.
Note: I already have some minor expirience with 3D in Unity, but I am a total newbie to 2D.
Thanks
There is no GDI/canvas implementation built into Unity. Drawing these in rastered 2D would be quite hard in Unity (basically putpixel level, or finding some third party library).
You have an alternative, though - you can draw these shapes in 3D, ignoring the third dimension. You have a few methods for this:
Line renderers - this one will be the easiest, but forget about anything else than just drawing the outline, no fill etc.
Make your own mesh - This will let you use the geometry with your scene. It's an retained mode API (you init your geometry once)
Use the GL namespace - This will be only rendered on the screen, no interaction with the scene. It's an immidiate mode API (draw everything on every frame)
How can I smooth a Graphics object in C# ? To be more precise, I need to run a smoothing at a very precise moment of my Graphics object generation, on the whole object. The image is coloured.
I am flexible in terms of input classes (Graphics, etc..). I just suggested Graphics at it is a central class for image manipulations in C#.
Graphics.SmoothingMode is out of context for what I need to do and I imagine WU's algorithm only applies to drawing lines in greyscale.
Have a look at the image processing features of AForge.Net. It is an open source framework that includes a lot of useful image processing capabilities. You will find many smoothing filters among them.
I think you used the wrong words to describe your problem. Anti aliasing refers to (as Hand mentioned) the point in time when individual objects are drawn for the first time. For instance, when drawing a diagonal line on an empty surface.
You already have an image, and you want that image to be smoothed. I suggest you detect edges in the image using a standard algorithm, then smooth those edges. I am not familiar with the exact process to do this myself, sadly.
Are there any libraries that utilize the the Canvases for Mono Android and MonoTouch? I am trying to draw node + edge network graphs and am hoping to avoid duplicating work by writing code to figure out methods for edge, node, and text placement (for labeling a node).
I'm not sure about the edge/node/text placement part of your question, but one project that's recently emerged is https://github.com/praeclarum/CrossGraphics which looks promising for sharing drawing code across the Mono mobile platforms:
Drawing commands include:
Rectangles using FillRect and DrawRect
Rounded Rectangles using FillRoundedRect and DrawRoundedRect
Ovals using FillOval and DrawOval
Lines using DrawLine and the option BeginLine and EndLine primitives
Images using DrawImage
Text using DrawString and the associated font
functions
I would like to do something like this: a rotating cube on a form. I don't want to use any external library or dll, just pure .NET 3.5 (without directx). And a cube build with lines only. Could you please tell me how to do this?
I don't want to use external libraries because I don't need > 100 MB library to do this thing right? I want only to animate a rotating cube made with lines.
This is how you go about making a Cube in GDI+
C# 3D Drawing with GDI+ Euler Rotation
http://www.vcskicks.com/3d-graphics-improved.html
C# 3D-Drawing Cube with Shading
http://www.vcskicks.com/3d_gdiplus_drawing.html
Study assignment? This can be done with some simple 3D maths. You just need to understand the basics of matrix algebra, 3D transformations, and 3D->2D view transformation. The DirectX tutorial covers this, but you can google for it and you'll get plenty of other tutorials.
Added: Just to clarify - I'm not suggesting to use DirectX or anything. You can do this with standard System.Drawing tools. You just need to understand the math, and that's explained in the DirectX tutorials.
You might try using WPF and the 3D Tools source code released by the WPF team.
3DTools
Assuming you are using WPF for your GUI:
Make an animated PNG of the cube using a graphics program.
Use the APNG WPF Control to insert the image into your GUI.
This will yield a small assembly size and transparent background if needed.
You need a way to represent 3d points. There is no ready struct for that in .NET unless you use directx or WPF.
Then with a standard euler rotation matrix applied to the points you get the transformed points. If you only do rotations you can get away with 3x3 matrix, but if you want translation you better use 4x4 matrices and homogenous points.
After this you need a way to project those 3d points to the 2d canvas. Depending whether you are using perspective or orthographic projection the projection matrix will look a bit different.
Look into WPF in general, it will help you do this with a few measly lines of code. You can also host a WPF window in Forms.
http://msdn.microsoft.com/en-us/library/aa970268.aspx