Rank: Advanced Member
Groups: Member
Joined: 5/29/2010(UTC) Posts: 1,310
Thanks: 8 times Was thanked: 111 time(s) in 111 post(s)
|
Hello Alex, 1. Quote: 1. Is there anyway that we can change the background without sacrificing those created layers? We need to allow the user to change the background, while editing the layers. At the moment, we cant think of any clue to fulfill this. Pls advise. In some time of thinking, we found a way which allows to change background with keeping objects :) Please replace RemoveAllRegions method with this one in the \GiftEditor\PhotoLabelControl.ascx.cs file: Code:
public void RemoveAllRegions(Dictionary<string, List<VObject>> vObjects)
{
for (int i = _canvasViewer.Canvas.Layers.Count - 1; i >= 0; i--)
{
Layer l = _canvasViewer.Canvas.Layers[i];
if (l != _photoLayer && l != _regionLayer && !string.IsNullOrEmpty(l.Name))
{
List<VObject> layerVObjects = new List<VObject>();
foreach (VObject vo in l.VObjects)
{
layerVObjects.Add(vo);
}
vObjects.Add(l.Name, layerVObjects);
_canvasViewer.Canvas.Layers.RemoveAt(i);
}
}
_regionLayer.VObjects.Clear();
}
And change templateRepeater_ItemCommand method in the \GiftEditor\PhotoLabelSample.aspx.cs: Code:
protected void templateRepeater_ItemCommand(object source, RepeaterCommandEventArgs e)
{
ClearTemplateSelection();
//change style of selected item
HtmlControl li = (HtmlControl)e.Item.FindControl("listItem");
if (string.IsNullOrEmpty(li.Attributes["class"]))
li.Attributes["class"] = "selectedTemplate";
else
li.Attributes["class"] += " selectedTemplate";
//get image file and regions
string file = null;
List<NamedRectangleRegion> regions = new List<NamedRectangleRegion>();
System.Globalization.NumberFormatInfo numberInfo = new System.Globalization.NumberFormatInfo();
numberInfo.NumberDecimalSeparator = ".";
string templatesListFile = Path.Combine(_templateFolder, "Templates.xml");
if (File.Exists(templatesListFile))
{
using (FileStream fs = new FileStream(templatesListFile, FileMode.Open, FileAccess.Read))
{
System.Xml.XPath.XPathDocument doc = new System.Xml.XPath.XPathDocument(fs);
foreach (XPathNavigator nav in
doc.CreateNavigator().Select("/Templates/TemplateItem"))
{
string fileName = Path.IsPathRooted(nav.GetAttribute("FileName", nav.NamespaceURI)) ? nav.Value : Path.Combine(_templateFolder, nav.GetAttribute("FileName", nav.NamespaceURI));
if (fileName.GetHashCode().ToString() == e.CommandArgument.ToString())
{
file = fileName;
foreach (XPathNavigator regionNavigator in nav.Select("Regions/Region"))
{
string name = regionNavigator.GetAttribute("Name", regionNavigator.NamespaceURI);
float left = float.Parse(
regionNavigator.GetAttribute("Left", regionNavigator.NamespaceURI), numberInfo);
float top = float.Parse(
regionNavigator.GetAttribute("Top", regionNavigator.NamespaceURI), numberInfo);
float width = float.Parse(
regionNavigator.GetAttribute("Width", regionNavigator.NamespaceURI), numberInfo);
float height = float.Parse(
regionNavigator.GetAttribute("Height", regionNavigator.NamespaceURI), numberInfo);
regions.Add(new NamedRectangleRegion(name,
new System.Drawing.RectangleF(left, top, width, height)));
}
break;
}
}
}
}
if (!string.IsNullOrEmpty(file) && File.Exists(file))
{
photoLabel.CanvasViewer.Canvas.History.Enable = photoLabel.CanvasViewer.Canvas.History.TrackingEnabled = false;
photoLabel.BackgroundImage = file;
Dictionary<string, List<VObject>> currentObjects = new Dictionary<string, List<VObject>>();
//remove previous regions
photoLabel.RemoveAllRegions(currentObjects);
//add new regions
photoLabel.AddRegions(regions);
//select last region
photoLabel.CurrentRegion = regions[regions.Count - 1];
// Restore objects
foreach (Layer layer in photoLabel.CanvasViewer.Canvas.Layers)
{
if (currentObjects.ContainsKey(layer.Name))
{
// Add object to this layer
foreach (VObject vo in currentObjects[layer.Name])
{
if (vo.Layer != null)
{
vo.Layer.VObjects.Remove(vo);
}
layer.VObjects.Add(vo);
}
}
}
//clear canvas history
photoLabel.CanvasViewer.Canvas.History.Clear();
photoLabel.CanvasViewer.Canvas.History.Enable = photoLabel.CanvasViewer.Canvas.History.TrackingEnabled = true;
}
}
2. Quote: For the text layer insertion, instead of RGB input, can we have a CMYK input? The color of textVobject is RGB only. Thus, even if you change input colors to CMYK, you should convert it back to RGB when add text to canvas. |
Best regards, Dmitry Obukhov
Technical Support. Aurigma, Inc.
|