Click here to Skip to main content
15,917,580 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a canvas in which I generate an image. I want to save this canvas in database as an object. Is it possible to do it in c#?

Thanks
Praveen
Posted
Updated 1-Apr-11 9:07am
v3
Comments
Albin Abel 1-Apr-11 13:46pm    
Is it a WPF question? If so add wpf tag as well.

How to save objects in a Canvas to database
Upload canvas element to webserver/database

I hope the above information will be helpful. If you have more concerns, please let me know.
 
Share this answer
 
If you have an image there are numerous articles showing how to add it to a database.

C# Photo Album Viewer[^]

Or are you asking how to convert the canvas to an image?
 
Share this answer
 
Thanks for the feedback. It helped me solve my issue. Below is what I opted to do:

Converted the control in to xaml and stored it in database. Later when required, pulled the xaml and recreated the control.

save to database
try
{
    string str = "";
    System.Windows.Controls.Canvas temp = new System.Windows.Controls.Canvas();
    temp = (System.Windows.Controls.Canvas)GraphArea.FindName("CANVASNAME");

    str = XamlWriter.Save(temp);//save the str to database



    GraphArea.Children.Remove(temp);
    GraphArea.UnregisterName(temp.Name);

}
catch (Exception exp)
{

}

End

Pull data from database and recreate the control
String strName = "";
  str = "";//pull XAML data from database
  System.Windows.Controls.Canvas canvas = System.Windows.Markup.XamlReader.Load(new System.Xml.XmlTextReader(new System.IO.StringReader(str))) as System.Windows.Controls.Canvas;
  strName = canvas.Name;
  GraphArea.Children.Add(canvas);
  GraphArea.RegisterName(strName, canvas);

End


Solution 2 is what I opted for.

http://forums.silverlight.net/forums/p/65180/160429.aspx[


Praveen
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900