Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic image not saved or loaded with saveToFile an loadFromfile (Read 7449 times)
hans
Junior Member
**
Offline


I Love MindFusion!

Posts: 81
Location: Netherlands
Joined: Mar 17th, 2012
image not saved or loaded with saveToFile an loadFromfile
Jan 16th, 2013 at 2:57pm
Print Post  
When I do  diagram.saveToFile(path) and then Diagram.loadFromFile(path) , all node.imagesUrls  are lost.
I check on the server and find that when saving the imageUrl exists, but after loading the imageUrl is lost.

        foreach (ShapeNode n in diagram.Nodes)
        {
            if (n.ImageUrl != null)
            {
                a = n.ImageUrl.ToString();
            }
        }
  
Back to top
 
IP Logged
 
hans
Junior Member
**
Offline


I Love MindFusion!

Posts: 81
Location: Netherlands
Joined: Mar 17th, 2012
Re: image not saved or loaded with saveToFile an loadFromfile
Reply #1 - Jan 16th, 2013 at 6:23pm
Print Post  
Also images (imageURL) get lost when executing:
        string a = diagram.SaveToString();
        diagram.LoadFromString(a);
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: image not saved or loaded with saveToFile an loadFromfile
Reply #2 - Jan 17th, 2013 at 6:57am
Print Post  
Currently this is not serialized in binary format. You could save diagrams in XML format for the time being, using the SaveToXml or SaveToString(SaveToStringFormat.Xml) methods.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
hans
Junior Member
**
Offline


I Love MindFusion!

Posts: 81
Location: Netherlands
Joined: Mar 17th, 2012
Re: image not saved or loaded with saveToFile an loadFromfile
Reply #3 - Jan 17th, 2013 at 2:19pm
Print Post  
I use
string a = diagram.SaveToString(SaveToStringFormat.Xml,false);
it results in almost the same as SaveToXml: the string has one line more at the beginning:
<?xml version="1.0" encoding="utf-16"?>

When I use diagram.LoadFromString(a) the images are lost.
(I first have to remove the first line, otherwise error)
Also LoadFromXml loses the images.

The imagesUrls are present in the xml
      <ImageUrl>images/rijbewijs2.bmp</ImageUrl>

any workaround ?
  
Back to top
 
IP Logged
 
hans
Junior Member
**
Offline


I Love MindFusion!

Posts: 81
Location: Netherlands
Joined: Mar 17th, 2012
Re: image not saved or loaded with saveToFile an loadFromfile
Reply #4 - Jan 17th, 2013 at 6:41pm
Print Post  
The problem seems to be with nodes for which the imageUrl is set by script, not for those set by code (asp.net c#)
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: image not saved or loaded with saveToFile an loadFromfile
Reply #5 - Jan 18th, 2013 at 8:03am
Print Post  
Calling this from the FractalLayout sample project, and then posting back and reloading worked in our test.

Code
Select All
var node = diagram.getFactory().createShapeNode(20, 20, 50, 50);
node.setImageLocation("./Images/pic4.png"); 



Are you sure the image location property isn't cleared at some later point in your code?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: image not saved or loaded with saveToFile an loadFromfile
Reply #6 - Jan 18th, 2013 at 1:29pm
Print Post  
What kind of error are you getting if you keep the xml declaration line?
  
Back to top
 
IP Logged
 
hans
Junior Member
**
Offline


I Love MindFusion!

Posts: 81
Location: Netherlands
Joined: Mar 17th, 2012
Re: image not saved or loaded with saveToFile an loadFromfile
Reply #7 - Jan 19th, 2013 at 1:18pm
Print Post  
The error I get when keeping the xml declaration line is:
[XmlException: There is no Unicode byte order mark. Cannot switch to Unicode.]
   System.Xml.XmlTextReaderImpl.Throw(Exception e) +69
   System.Xml.XmlTextReaderImpl.ThrowWithoutLineInfo(String res) +105
   System.Xml.XmlTextReaderImpl.CheckEncoding(String newEncodingName) +261
   System.Xml.XmlTextReaderImpl.ParseXmlDeclaration(Boolean isTextDecl) +1839
   System.Xml.XmlTextReaderImpl.Read() +340
   System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace) +145
   System.Xml.XmlDocument.Load(XmlReader reader) +107
   System.Xml.XmlDocument.Load(String filename) +122
   MindFusion.Diagramming.Diagram.LoadFromXml(String fileName, Boolean loadDiagramProperties) +77
   MindFusion.Diagramming.Diagram.LoadFromXml(String fileName) +39
   Default2.btnLoad_Click(Object sender, EventArgs e) in c:\Users\admin\Documents\Visual Studio 2012\WebSites\canvas\Default2.aspx.cs:54
  
Back to top
 
IP Logged
 
hans
Junior Member
**
Offline


I Love MindFusion!

Posts: 81
Location: Netherlands
Joined: Mar 17th, 2012
Re: image not saved or loaded with saveToFile an loadFromfile
Reply #8 - Jan 19th, 2013 at 1:33pm
Print Post  
I have to correct some things in this posting:
This works correct, inluding ImageLocation
        string a = diagram.SaveToString(SaveToStringFormat.Xml, false);
        diagram.LoadFromString(a);

This also works correct inluding ImageLocation:
diagram.SaveToXml(filename)
diagram.LoadFromXml(filename)

My confusion was that I copied the images from one node to another by:  node2.setImage(node1.getImage);
The image showed well in the diagram, but got lost when saving and loading.
I should have used
node2.setImageLocation(node1.getImageLocation);

The only issue left is: If I write a SaveToString(SaveToStringFormat.Xml)  to file  and load it with loadFromXML, I get the Unicode-Error.

I don't use it anymore.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: image not saved or loaded with saveToFile an loadFromfile
Reply #9 - Jan 20th, 2013 at 10:18am
Print Post  
I suppose you are not saving the Xml string into a Unicode file then. If you call SaveToString(Xml) and save the string into non-unicode text file, you can still load the diagram using a symmetrical method - first read the file into a .NET String (which is always Unicode) using StreamReader.ReadToEnd method, and then call diagram.LoadFromString(theString). Alternatively just save into a Unicode16 file via the StreamWriter(path, encoding) constructor.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint