logo
small logo
  • Producto
  • Comprar
  • Ayuda
  • Blogs
  • Consola de usarios Ayuda
    • en
    • ru
    • pt
    • es
    • de
    • pl
    • JP
    • ZH
  • Página principal
  • /
  • Blogs
  • /
  • Gráficos vectorales en FastReport.Net 2019.4. Script
  • How to connect to SQLCe

    11 de noviembre de 2019

    Microsoft SQL Server Compact Edition is a simple local relational database that doesn't require installation,

    read more
  • How to connect to the Sybase SQL Anywhere database

    29 de febrero de 2020

    Sybase SQL Anywhere database has a number of very useful features that make it very

    read more
  • Create a new report with code VB.Net

    17 de septiembre de 2020

    Speaking of the .Net framework, we usually imagine the #C programming language. Simply because the

    read more
  • How to disable printing reports and other items from the menu when viewing the report FastReport.Net

    29 de febrero de 2020

    The main report viewing tool FastReport.Net is Viewer. This viewer has a rich toolkit for

    read more
  • How to update the FastReport.Core web report

    21 de septiembre de 2020

    Sometimes you need to update the report, for example if you input a new variable

    read more

Gráficos vectorales en FastReport.Net 2019.4. Script

30 de julio de 2019

En la primera parte del artículo hemos revisado las novedades de FastReport.Net 2019.4 en términos de gráficos vectorales. Ahora polilíneas y polígonos se pueden construir por curvas de Bezier. En este artículo vamos a echar un vistazo a la posibilidad de crear curvas utilizando un script de informe.

Actualmente hay dos maneras de crear curvas de un código: utilizando un objeto PolyLineObject o cargando un poligón desde un SVG.

Como sabe, cualquier objeto de informe está disponible en el script del informe, por lo cual podemos utilizar PolyLineObject para especificar puntos y conectarlos para crear una figura. Ejecute el código antes de mostrar el objeto. Por lo tanto, hay que crear un manipulador de eventos BeforePrint para el objeto Polygon. Vamos a considerar un ejemplo. Tiene que ejecutar el código antes de mostrar el objeto. De esta manera, hay que crear un manipulador de eventos BeforePrint para el objeto Polygon. Aquí tiene el ejemplo:

Añada un objeto Polygon a la página del informe. Para no crear puntos claves de la figura, simplemente presione Esc. En el ispectador de las propiedades del objeto seleccione un evento. Creee una manipulador de eventos BeforePrint:

 

Vamos a escribir el siguiente código en el manipulador:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
private void Polygon4_BeforePrint(object sender, EventArgs e)
 {
 // Create a star shape
 int spikes = 5; //Number of spikes
 PolyLineObject obj = sender as PolyLineObject;
 PolyLineObject.PolyPointCollection points = obj.Points;
 points.Clear();
 const float outerRadius = 70; //External radius
 const float innerRadius = 30; //Internal radius
 float rot = (float)(Math.PI / 2 * 3); // Tilt angle
 const float cx = 0;
 const float cy = 0;
 float x = cx;
 float y = cy;
 float step = (float)(Math.PI / spikes); // Vertex creation step
 obj.Width = 100;
 obj.Height = 100;
 obj.CenterX = 50;
 obj.CenterY = 50;
 points.Add(new PolyLineObject.PolyPoint(cx, cy - outerRadius)); //Add points
 for (int i = 0; i < spikes; i++)
 {
 // Coordinates of interior points
 x = cx + (float)Math.Cos(rot) * outerRadius;
 y = cy + (float)Math.Sin(rot) * outerRadius;
 points.Add(new PolyLineObject.PolyPoint(x, y));
 rot += step; // Next point
 // Coordinates of external points
 x = cx + (float)Math.Cos(rot) * innerRadius;
 y = cy + (float)Math.Sin(rot) * innerRadius;
 points.Add(new PolyLineObject.PolyPoint(x, y));
 rot += step;
 }
 }

Cómo resultado obtenemos una estrella:

 

En el ejemplo de arriba hemos calculado las coordenadas para construir la figura, pero si ya tiene una lista de coordenadas, entonces simplemente añádalas al conjunto de puntos: Add (new PolyLineObject.PolyPoint(x, y));

¿Pero qué pasa si la figura es mucho más complicada que en el ejemplo dado? El tamaño del código para crearla debe de ser demasado grande. En este caso puede utilizar el objeto SVG. Por ejemplo, su propiedad path. Podemos convertir un conjunto de elementos de la ruta de la imágen .svg en puntos y construir un polígono según estos. Es importante tener en cuenta puntos de Bezier. Vamos a ver cómo realizarlo en el código de abajo:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
private void PolyLine2_BeforePrint(object sender, EventArgs e)
 {
 PolyLineObject obj = sender as PolyLineObject;
 PolyLineObject.PolyPointCollection points = obj.Points;
 points.Clear ();
 // Svg builder along the way
 SvgPathBuilder builder = new SvgPathBuilder ();
 // Load the list of segments from the string
 SvgPathSegmentList list = builder.ConvertFromString ("M91.734 10.5L66.6384 59.025 10.5 66.8258l40.643 37.749-9.5696 53.327 50.2094-25.1932 50.234 25.1582-9.6124-53.321 40.6154-37.778-56.1505-7.76z") as SvgPathSegmentList; 
 GraphicsPath _path = new GraphicsPath ();
 foreach (SvgPathSegment segment in list) {
 segment.AddToPath (_path);
 }
 PolyLineObject.PolyPoint point = null;
 for (int i = 0; i < _path.PointCount; i++) {
 PointF pnt = _path.PathPoints[i];
 byte type = _path.PathTypes[i];
 // If you have a curve, you have to consider three contractors.
 if (type == 3) {
 PointF pnt1 = _path.PathPoints[i];
 PointF pnt2 = _path.PathPoints[i + 1];
 PointF pnt3 = _path.PathPoints[i + 2];
 i += 2;
 // Curvature to the right
 point.RightCurve = new PolyLineObject.PolyPoint (pnt1.X - point.X,
 pnt1.Y - point.Y);
 //Point
 point = new PolyLineObject.PolyPoint (pnt3.X, pnt3.Y);
 // Curvature to the left
 point.LeftCurve = new PolyLineObject.PolyPoint (pnt2.X - point.X,
 pnt2.Y - point.Y);
 } else {
 // Ordinary point
 point = new PolyLineObject.PolyPoint (pnt.X, pnt.Y);
 }
 // Add points
 points.Add (point);
 }
 obj.CenterX = 0;
 obj.CenterY = 0;
 obj.RecalculateBounds ();
 obj.Top = 0;
 obj.Left = 0;
 }
 }

Este código hará aparecer una estrella de este tipo:

 

En la lista del tipo SvgPathSegmentList ubicamos elementos de la etiqueta path del archivo SVG. A continuación obtenemos las coordinadas de los puntos y los añadimos al objeto PolyLine. En este ejemplo hemos mostrado el objeto con líneas rectas, pero también se puede utilizar curvas, por ejemplo:

…

      SvgPathSegmentList list = builder.ConvertFromString ("m101.87775,57.26873c31.12829,-82.10042 153.08994,0 0,105.55768c-153.08994,-105.55768 -31.12829,-187.65809 0,-105.55768z") as SvgPathSegmentList;     

…

Tenemos como resultado lo siguiente:

 

Hay que tener en cuenta que el plano coordenado es la bandaen la que están los objetos Polyline y Polygon. Por lo tanto, no importa el lugar preciso en el que ha ubicado el objeto. Se muestra de acuerdo con las coordenadas especificadas.

Utilizando el segundo método de crear un polígono de un script, podrá mostrar dibujos vectorales creados préviamente. Así, no debe gastar su tiempo en crear un polígono a mano.

about product descargar comprar
avatar
Dmitriy Fedyashov
.NET FastReport Vector graphic Script

Add comment
logo
  • 800-985-8986 (English, US)
  • +4930568373928 (German)
  • +55 19 98147-8148 (Portuguese)
  • info@fast-report.com
  • 901 N Pitt Str #325 Alexandria VA 22314
  • Comprar
  • Descargar
  • Documentación
  • Opiniones de usuarios
  • Cómo desinstalar nuestros productos
  • Enviar mensaje
  • FAQ
  • Toturial en vídeo
  • Foro
  • Documentación técnica
  • Nuestras noticias
  • Quiénes somos
  • Socios
  • Nuestro equipo
  • Contactos

© 1998-2021 by Fast Reports Inc.

  • Privacidad