How to fill a custom shape with color or texture?


Author
Message
Marius Bucur
Marius Bucur
Junior Member (12 reputation)Junior Member (12 reputation)Junior Member (12 reputation)Junior Member (12 reputation)Junior Member (12 reputation)Junior Member (12 reputation)Junior Member (12 reputation)Junior Member (12 reputation)Junior Member (12 reputation)
Group: Forum Members
Posts: 12, Visits: 1
I am trying to fill a custom shape with color or a texture, but so far i have no luck. Basically my code look like this:

GraphicsPath graphicsPath = new GraphicsPath();

PointF[] points = new PointF[]
{
new PointF(0, 0),
new PointF(0, 20),
new PointF(20, 20),
new PointF(20, 0),
};
graphicsPath.AddPolygon(points);
//InitTextures();
NCompositeShape shape = new NCompositeShape();
shape.Primitives.AddChild(new NCustomPath(graphicsPath, PathType.OpenFigure));
shape.UpdateModelBounds();
//NImageFillStyle img = new NImageFillStyle(this.textures["bricks"] as Bitmap);
//img.TextureMappingStyle.MapMode = MapMode.RelativeToObject;
//shape.Style.FillStyle = img;
shape.Name = "Basic Wall";
shape.Text = "Basic Wall";


shape.Style.FillStyle = new NColorFillStyle(Color.AliceBlue);
shape.Style.StrokeStyle = new NStrokeStyle(1, Color.FromArgb(0, 0, 0x88));
Ivo Milanov
Ivo Milanov
Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)
Group: Forum Members
Posts: 35, Visits: 32
Hi Marius,

The custom path you create must be marked as ClosedFigure if the diagram is to attempt to fill the path interior:

NCompositeShape shape = new NCompositeShape();
shape.Primitives.AddChild(new NCustomPath(graphicsPath, PathType.ClosedFigure));

Best regards,
Ivo
Marius Bucur
Marius Bucur
Junior Member (12 reputation)Junior Member (12 reputation)Junior Member (12 reputation)Junior Member (12 reputation)Junior Member (12 reputation)Junior Member (12 reputation)Junior Member (12 reputation)Junior Member (12 reputation)Junior Member (12 reputation)
Group: Forum Members
Posts: 12, Visits: 1
nvm, its solved. I should be using PathType.ClosedFigure in this line: shape.Primitives.AddChild(new NCustomPath(graphicsPath, PathType.OpenFigure));

But i have another question, is it possible to make a texture pattern repeat and not stretch when i resize the custom shape ?
Ivo Milanov
Ivo Milanov
Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)
Group: Forum Members
Posts: 35, Visits: 32
Check out this topic in the .NET Vision Documentation:

Framework > Presentation Layer > Graphics > Appearance Styles > Fill Styles > Texture Mapping Style

It basically outlines the possible ways in which a texture can be mapped. To make the image Tiled used this code:

NImageFillStyle imageFill = ...;
imageFill.TextureMappingStyle.MapLayout = MapLayout.Tiled;

Best regards,
Ivo
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search