PathResourceConverter

PathResourceConverter class

ConviertePathResource aGraphicsPath y viceversa.

public static class PathResourceConverter

Métodos

NombreDescripción
static FromGraphicsPath(GraphicsPath, Size)Convierte elGraphicsPath instancia a la ruta recursos.
static ToGraphicsPath(PathResource[], Size)Convierte los recursos de la ruta alGraphicsPath instancia.

Ejemplos

Cree una ruta de gráficos a partir de recursos de ruta en una imagen TIFF.

[C#]

using (var image = (TiffImage)Image.Load("Bottle.tif"))
{
    // Crea GraphicsPath usando PathResources desde una imagen TIFF
    var graphicsPath = PathResourceConverter.ToGraphicsPath(image.ActiveFrame.PathResources.ToArray(), image.ActiveFrame.Size);
    var graphics = new Graphics(image);

    // Dibujar línea roja y guardar la imagen
    graphics.DrawPath(new Pen(Color.Red, 10), graphicsPath);
    image.Save("BottleWithRedBorder.tif");
}

Cree recursos de ruta utilizando la ruta de gráficos.

[C#]

static void Main(string[] args)
{
    using (var image = (TiffImage)Image.Load("Bottle.tif"))
    {
        // Crear figura rectangular para GraphicsPath
        var figure = new Figure();
        figure.AddShape(CreateBezierShape(100f, 100f, 500f, 100f, 500f, 1000f, 100f, 1000f));

        // Crear GraphicsPath usando nuestra Figura
        var graphicsPath = new GraphicsPath();
        graphicsPath.AddFigure(figure);

        // Establecer PathResources usando GraphicsPath
        var pathResouze = PathResourceConverter.FromGraphicsPath(graphicsPath, image.Size);
        image.ActiveFrame.PathResources = new List<PathResource>(pathResouze);

        // Guarda la imagen
        image.Save("BottleWithRectanglePath.tif");
    }
}

private static BezierShape CreateBezierShape(params float[] coordinates)
{
    var bezierPoints = CoordinatesToBezierPoints(coordinates).ToArray();
    return new BezierShape(bezierPoints, true);
}

private static IEnumerable<PointF> CoordinatesToBezierPoints(float[] coordinates)
{
    for (var coordinateIndex = 0; coordinateIndex < coordinates.Length; coordinateIndex += 2)
        for (var index = 0; index < 3; index++)
            yield return new PointF(coordinates[coordinateIndex], coordinates[coordinateIndex + 1]);
}

Ver también