I added the background image for each product by the help of Item.Icon.Image command. But i cant save the image into XML file. we are using following for add the label into item. How to store image files.
t = new GoXmlBindingTransformer("item", new Item());
t.IdAttributeUsedForSharedObjects = true; // each Item gets a unique ID
t.AddBinding("label", "Text");
t.AddBinding("iconname", "Icon.Name");
t.AddBinding("iconindex", "Icon.Index"); // assumes an ImgeList is set up for Item
t.AddBinding("size", "Size");
t.AddBinding("location", "Location");
AddBrushBindings(t, "brush", "Back");
rw.AddTransformer(t);
Are your images coming from resource files, or on-disk (external to the application) files?
Image is load from External files. For each Type of product get individual images.
The code the way the sample is (and the way you have it) should work for ondisk files.
e.g.
I already added the icon for the individual product. After completed the planogram Design. The Designed planogram save the following type .plan, .bmp. On that time the design also write in the form of XML. Please refer the following code that is given by your developers.
//Helps to save the Planogram image into XML
public void StoreXml(FileStream ofile) {
GoXmlWriter xw = new GoXmlWriter();
InitReaderWriter(xw);
xw.Objects = this;
xw.Generate(ofile);
}
To extend GoXmlBindingTransformer to support a type it doesn’t know, you have to derive a new class and add the attributes support there.
Like this:
public class GoXmlBindingTransformerImage : GoXmlBindingTransformer {
public GoXmlBindingTransformerImage(String eltname, Object proto) : base (eltname, proto) {
}
}
public override void GenerateAttributes(object obj) {
base.GenerateAttributes(obj);
Item i = obj as Item;
if (i != null) {
MemoryStream stream = new MemoryStream();
i.Icon.Image.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
stream.Close();
byte[] bdata = stream.GetBuffer();
string bits = Convert.ToBase64String(bdata);
WriteAttrVal("bits", bits);
}
}
base.GenerateAttributes(obj);
Item i = obj as Item;
if (i != null) {
MemoryStream stream = new MemoryStream();
i.Icon.Image.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
stream.Close();
byte[] bdata = stream.GetBuffer();
string bits = Convert.ToBase64String(bdata);
WriteAttrVal("bits", bits);
}
}
public override void ConsumeAttributes(object obj) {
base.ConsumeAttributes(obj);
base.ConsumeAttributes(obj);
Item i = obj as Item;
if (i != null) {
String bits = StringAttr("bits", null);
if (bits != null) {
byte[] bytes2 = Convert.FromBase64String(bits);
MemoryStream stream = new MemoryStream(bytes2);
i.Icon.Image = Image.FromStream(stream);
stream.Close();
}
}
}
if (i != null) {
String bits = StringAttr("bits", null);
if (bits != null) {
byte[] bytes2 = Convert.FromBase64String(bits);
MemoryStream stream = new MemoryStream(bytes2);
i.Icon.Image = Image.FromStream(stream);
stream.Close();
}
}
}
} // end of GoXmlBindingTransformerImage
then use GoXmlBindingTransformerImage as the trasnformer for the Item class.
Note that I use PNG as the storage format, that should be able to handle ico, bmp, etc.
One thing I haven't done here is attempt to save space in the xml by sharing common bitmaps.
Hi Jake,
Thank you for your code. Now its working really great... I got the great look and feel for my planogram design.