Best way to use a background image in a diagram


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 implement a diagram that will help my customers to set up various furniture in a building. To easy the work I am trying to use the floor plans as a background, so the user can easily place the shapes of furniture in the rooms. What i am doing now is to upload the image in the background of the document and set up layers for various shapes. But at some point i need to hide the document background so the user can see only the shapes he created.
Right now I don't know how to hide the background. I have tried with document.BackgroundStyle.FillStyle.Dispose() but it doesn't seem to do the trick, also document.BackgroundStyle.FillStyle.SetTransparencyPercent(100.0F) but this clears also the document background color.

What i really like to do is to assign the background image to a default layer and display that only when i need. It seems that this is not possible though since the background is scaling to the the area that have controls draw on it.

Any idea how to better implement this thing?
Pavel Vladov
Pavel Vladov
Forum Member (34 reputation)Forum Member (34 reputation)Forum Member (34 reputation)Forum Member (34 reputation)Forum Member (34 reputation)Forum Member (34 reputation)Forum Member (34 reputation)Forum Member (34 reputation)Forum Member (34 reputation)
Group: Forum Members
Posts: 33, Visits: 2

Hi Marius,

In your case it is better to create a new layer for the background. Thus you will be able to easily show or hide this layer. For more information about using layers take a look at the online documentation.

I hope this helps, let me know if you have any questions.

Cheers,
Pavel


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
It doesn't help at all.
Let me be more clear: I use layers and I draw shapes in layers accordingly to my needs.
The problem is that i don't know how to add a background to a layer and this background cover all the document size.

Right now i use the following piece of code to add background to a layer:

private NLayer CreateNewLayer(NDrawingDocument document)
{
this.currentLayerNumber = this.currentLayerNumber + 1;
NLayer newLayer = new NLayer();
newLayer.Name = "Layer " + this.currentLayerNumber.ToString();
newLayer.Style.StrokeStyle = new NStrokeStyle(1, Color.FromArgb(0xaa, 0x00, 0x00));
newLayer.Style.FillStyle = new NColorFillStyle(Color.FromArgb(0xff, 0x99, 0x77));
newLayer.Style.ShadowStyle = new NShadowStyle(ShadowType.None, Color.Black, new NPointL(3, 3));

NImageFillStyle imageFrameStyle = new NImageFillStyle("floorplan.jpg");
imageFrameStyle.TextureMappingStyle.MapMode = MapMode.RelativeToViewer;
newLayer.Style.FillStyle = imageFrameStyle;
//this.hasBackground = true;

// add it to the document and make it the active one
document.Layers.AddChild(newLayer);
document.ActiveLayerUniqueId = newLayer.UniqueId;

// add a rectangle
NRectangleShape shape = new NRectangleShape(currentLayerNumber * 11, 1, 10, 10);
shape.Style.TextStyle = new NTextStyle(new Font("Ariel", 100), Color.FromArgb(150, 150, 150));
shape.Text = currentLayerNumber.ToString();
document.ActiveLayer.AddChild(shape);

document.RefreshAllViews();

return newLayer;
}

But the result is that the background image is only shown in the shape area like in the image bellow:

http://ygo.ro/images/wrong.jpg
Pavel Vladov
Pavel Vladov
Forum Member (34 reputation)Forum Member (34 reputation)Forum Member (34 reputation)Forum Member (34 reputation)Forum Member (34 reputation)Forum Member (34 reputation)Forum Member (34 reputation)Forum Member (34 reputation)Forum Member (34 reputation)
Group: Forum Members
Posts: 33, Visits: 2
Marius, I'm afraid you are not getting right the concept of styles and style inheritance used in our diagramming component. Shortly said when you set the fill style of the layer, then you simply set the fill style that will be used by all of its children by default. For a more thorough reading on styles and style inheritance click here.

Now back to the question - if you want the layer to fill the whole document you simply create a rectangle path and fill it with the image you want. I'll give you an example with the code snippet you've posted. It should look as follows:


private NLayer CreateNewLayer(NDrawingDocument document)
{
NLayer newLayer = new NLayer();
newLayer.Name = "Layer " + (++currentLayerNumber).ToString();
newLayer.Style.StrokeStyle = new NStrokeStyle(1, Color.FromArgb(0xaa, 0x00, 0x00));
newLayer.Style.FillStyle = new NColorFillStyle(Color.FromArgb(0xff, 0x99, 0x77));
newLayer.Style.ShadowStyle = new NShadowStyle(ShadowType.None, Color.Black, new NPointL(3, 3));

// add it to the document and make it the active one
document.Layers.AddChild(newLayer);
document.ActiveLayerUniqueId = newLayer.UniqueId;

// add the background rectangle
NImageFillStyle imageFrameStyle = new NImageFillStyle("D:\\car.jpg");
imageFrameStyle.TextureMappingStyle.MapMode = MapMode.RelativeToViewer;
NRectanglePath rect = new NRectanglePath(document.Bounds);
NStyle.SetFillStyle(rect, imageFrameStyle);
NStyle.SetStrokeStyle(rect, new NStrokeStyle(KnownArgbColorValue.Transparent));
newLayer.AddChild(rect);

// add a rectangle
NRectangleShape shape = new NRectangleShape(currentLayerNumber * 11, 1, 10, 10);
shape.Style.TextStyle = new NTextStyle(new Font("Arial", 100), Color.FromArgb(150, 150, 150));
shape.Text = currentLayerNumber.ToString();
newLayer.AddChild(shape);

document.RefreshAllViews();

return newLayer;
}


If you have any other questions let me know.

Cheers,
Pavel
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
Thank you for the reply, that does the trick.
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