about ImageBasedShape FullPath

Oct 7, 2015 at 3:01 PM
Hi,

Running NShape Designer,
1) new project, if I try to add one Picture(ImageBasedShape), and add one image and save project, error happen.

2) new project, if I try to add one Picture(ImageBasedShape), save, and add one image which give a different file path from project, and save again and reload, error.

In the property grid, Image only give a image name, not include full path name,
I am NamedImage class full path, how to include full path of image name?

Thanks.
Coordinator
Oct 9, 2015 at 9:12 AM
Hi.

Thanks for your feedback. We can reproduce the error and will fix it as soon as possible.
Running NShape Designer,
1) new project, if I try to add one Picture(ImageBasedShape), and add one image and save project, error happen.
Workarounds:
a) Save your project before assigning images.
b) Uncheck "File > Use Embedded Images" before saving. This creates a directory containing the images next to the project file (*.nspj).
c) In your application, you could also combine a) and b): Save without embedded images first, then save again WITH embedded images and delete the image directory.
Please let me know if one of these options is acceptable to you for the moment.
2) new project, if I try to add one Picture(ImageBasedShape), save, and add one image which give a different file path from project, and save again and reload, error.
You should not change the FilePath after the image was saved as the image will be eventually loaded from this path (depending on the type of Store). This can be a 'real' file path but also a tag name (embedded images) or a path relative to the project file location.
In the property grid, Image only give a image name, not include full path name,
I am NamedImage class full path, how to include full path of image name?
In NShape Designer / PropertyGrid, you have to click the [...] Button of the shape's "Image" property and then the [...] button of the dialog window.
Select the image using the 'open file' dialog. The image name will be filled automatically, the image file path is neither displayed to nor editable by the user.

In code, you can use one of these methods:
string imagePath = "C:\\Image.png";
NamedImage img = null;
// Load image from file
img = NamedImage.FromFile(imagePath);
img = new NamedImage(imagePath);
// Save loaded bitmap to file
NamedImage img = new NamedImage(Bitmap.FromFile(imagePath), "My Image");
img.Save("C:\\Temp\\", ImageFormat.Png);    // This will set img.FilePath to "C:\Temp\My Image.png"
Please note that the image file path is the path from which the image will be loaded and therefore can change when the repository is saved (depending on the type of store). Images will be copied when saving.

Hope this helps.
Best regards,
Kurt
Oct 9, 2015 at 3:50 PM
Thanks for your reply, actually I think question 1) is a bug, it would be nice to fix it, otherwise user will be forced to save firstly and put image later.
In the code, I guess it could be related with set NamedImage id, in the file XmlStore.cs, WriteEmbeddedEntityImages(...), entity.Id is null,
but I cannot simply add "if (entity.Id == null) entity.AssignId(Guid.NewGuid());" because later, entity.Id will be set a different GUID, conflict error.

Actually my real requirement is:
I want to create a Shape class which can embedded a predefined EMF file and include 9 control points(like pictureBase)
There could be 2 ways:
way 1) I have already done this: put all custom image files (EMF/JPG) to one dir, and create my own library dll which can load all those images
to VectorImage class, the shortcoming is VectorImage only have one control point to enlarge, it would be nice have 9 control points like RectangleBase class.

way 2) so I want to used pictureBase as my class then I meet NamedImage entity id is null error.
I think maybe using existing pictureBase is easier.

the reason why I want to have 9 control points is, suppose we have many custom symbols(EMF format), with different control point position or different number, the end user may need a way (a tool) to define there own control points, then developer must provide with a tool, to do that, developer may need
define their own shape class, and pictureBase could be a good entrance point, what's your suggestion?

Best regards
one developer
Coordinator
Oct 12, 2015 at 2:34 PM
actually I think question 1) is a bug, it would be nice to fix it,
Yes, this is a bug and yes, we will fix it. As I said: "We can reproduce the error and will fix it as soon as possible."
otherwise user will be forced to save firstly and put image later.
Not necessarily: The bug will occur only if you use the "Embedded images" feature.
If you do not insist on having a single project file, you can deactivate "Use Embedded Images" (NShape Designer) / set XmlStore.ImageLocation to ImageFileLocation.Directory.
In this case, the project will be saved to a XML file and a related directory containing all images.
You could also implement a loading/saving projects in your application using zip files, e.g. loading a project will unzip the project files to the TEMP directory where the NShape XmlStore component will open it. When saving, the NShape XmlStore component will save the project files to the temp directory where your application creates a zip file which will be saved to whereever the user wants to.
Just an idea...
In the code, I guess it could be related with set NamedImage id, in the file XmlStore.cs, WriteEmbeddedEntityImages(...), entity.Id is null,
but I cannot simply add "if (entity.Id == null) entity.AssignId(Guid.NewGuid());" because later, entity.Id will be set a different GUID, conflict error.
No, unfortunately, it's not that simple. But we are aware of the problem and will find a solution.
way 1) I have already done this: put all custom image files (EMF/JPG) to one dir, and create my own library dll which can load all those images
to VectorImage class, the shortcoming is VectorImage only have one control point to enlarge, it would be nice have 9 control points like RectangleBase class.
You can implement the control points yourself by overriding
Shape.CalcControlPoints: Calculate the untransformed positions of the control points relative to (0;0)
Shape.HasControlPointCapability: Determine how the control point behaves.
Shape.ControlPointCount
way 2) so I want to used pictureBase as my class then I meet NamedImage entity id is null error.
I think maybe using existing pictureBase is easier.
The Picture shape is more flexible and has more features 'out of the box' but on the other hand, you have to put more effort in restricting the user's actions (e.g. prevent the end user to change the shape's image).
If the images do not change, have a look at this topic of the documentation:
Programmer Tasks > Customizing the Toolbox, especially the topic "Loading a Template Project".
the reason why I want to have 9 control points is, suppose we have many custom symbols(EMF format), with different control point position or different number,
the end user may need a way (a tool) to define there own control points, then developer must provide with a tool, to do that, developer may need
define their own shape class, and pictureBase could be a good entrance point, what's your suggestion?
Yes, PictureBase is a good class to start with because it has the full feature set (unlike the VectorImage which has more or less minimum feature set).
On the other hand, implementing your own shape library gives you a lot more flexibility.
Coordinator
Oct 30, 2015 at 8:05 AM
The bug you reported above is fixed now.
In case you need a quick fix, please send an email to "support at dataweb dot de" containing a short note that you need the bugfix for the NShape XML store. I'll send you the corrected files then.
We also plan a new release but I cannot tell you now when it will be released exactly.
Nov 4, 2015 at 1:54 AM
Thank you, what's your email? It would be nice if you can email me those updated files.
Coordinator
Nov 13, 2015 at 7:20 AM
Still out there?
I've contacted you via Codeplex but never got a reply. Perhaps the mail got stuck in a spam filter?
Anyway, as I wrote above: The adress is "support (at) dataweb (dot) de". Don't forget to add a subject to the mail, otherwise there is a chance that our spam filter will filter it.
Coordinator
Nov 20, 2015 at 12:17 PM
Edited Nov 20, 2015 at 12:17 PM
Sorry, I can't send the email to the provided adress ...(at)qq.com because the mail server rejects it with the error message "550 Ip frequency limited."
Do you have an other email adress?
Nov 20, 2015 at 3:21 PM
I can read this email, my email address is: [email removed] 2015-11-20 21:17 GMT+08:00, KurtHolzinger <[email removed]>: