i want to save a image form serialization....
-
Thats nice. Not really a question though is it? So, where about are you? Do you have a stream which represents the image? If so, how did you get that image into the stream in the first place? You've got to give at least a little bit of information to get any help.
My current favourite word is: Nipple!
-SK Genius
-
Thats nice. Not really a question though is it? So, where about are you? Do you have a stream which represents the image? If so, how did you get that image into the stream in the first place? You've got to give at least a little bit of information to get any help.
My current favourite word is: Nipple!
-SK Genius
[Serializable] public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Paint(object sender, PaintEventArgs e) { draw(); } public void draw() { Graphics g = this.CreateGraphics(); Pen p = new Pen(Color.Red); g.DrawRectangle(p, 23, 23, 78, 78); } using System.IO; using System.Xml.Serialization; public partial class Form2 : Form { public Form2() { InitializeComponent(); } private static void Serialize() { Form1 obj = new Form1(); XmlSerializer mySerializer = new XmlSerializer(typeof(Form1)); StreamWriter myWriter = new StreamWriter("C:\\myDrawing.xml"); mySerializer.Serialize(myWriter, obj); myWriter.Close(); } private static void DeSerialize() { Form1 obj = null; XmlSerializer mySerializer = new XmlSerializer(typeof(Form1)); FileStream myFileStream = new FileStream("C:\\myDrawing.xml", FileMode.Open); obj= (Form1)mySerializer.Deserialize(myFileStream); obj.Draw(); } private void Form2_Load(object sender, EventArgs e) { Serialize(); // Form1 f = new Form1(); // putIt objDele = new putIt(f.toi); //objDele(); } private void button1_Click(object sender, EventArgs e) { DeSerialize(); } } now i think its enough for understanding ?
hghghgh
-
[Serializable] public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Paint(object sender, PaintEventArgs e) { draw(); } public void draw() { Graphics g = this.CreateGraphics(); Pen p = new Pen(Color.Red); g.DrawRectangle(p, 23, 23, 78, 78); } using System.IO; using System.Xml.Serialization; public partial class Form2 : Form { public Form2() { InitializeComponent(); } private static void Serialize() { Form1 obj = new Form1(); XmlSerializer mySerializer = new XmlSerializer(typeof(Form1)); StreamWriter myWriter = new StreamWriter("C:\\myDrawing.xml"); mySerializer.Serialize(myWriter, obj); myWriter.Close(); } private static void DeSerialize() { Form1 obj = null; XmlSerializer mySerializer = new XmlSerializer(typeof(Form1)); FileStream myFileStream = new FileStream("C:\\myDrawing.xml", FileMode.Open); obj= (Form1)mySerializer.Deserialize(myFileStream); obj.Draw(); } private void Form2_Load(object sender, EventArgs e) { Serialize(); // Form1 f = new Form1(); // putIt objDele = new putIt(f.toi); //objDele(); } private void button1_Click(object sender, EventArgs e) { DeSerialize(); } } now i think its enough for understanding ?
hghghgh
Here you are serialising form1 - i.e. serialising its properties (text, size, position etc). This does not serialise the graphics. I suggest that if you want to save the graphics drawn at runtime you look at putting them into a bitmap, and saving that instead of using serialisation. Chris
-
Here you are serialising form1 - i.e. serialising its properties (text, size, position etc). This does not serialise the graphics. I suggest that if you want to save the graphics drawn at runtime you look at putting them into a bitmap, and saving that instead of using serialisation. Chris
-
Do your drawing to a bitmap as suggested. Have a property of byte array. Save the bitmap to a memory stream and use the stream's ToArray method to set the data in your property. It should then serialize OK.
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) -
[Serializable] public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Paint(object sender, PaintEventArgs e) { draw(); } public void draw() { Graphics g = this.CreateGraphics(); Pen p = new Pen(Color.Red); g.DrawRectangle(p, 23, 23, 78, 78); } using System.IO; using System.Xml.Serialization; public partial class Form2 : Form { public Form2() { InitializeComponent(); } private static void Serialize() { Form1 obj = new Form1(); XmlSerializer mySerializer = new XmlSerializer(typeof(Form1)); StreamWriter myWriter = new StreamWriter("C:\\myDrawing.xml"); mySerializer.Serialize(myWriter, obj); myWriter.Close(); } private static void DeSerialize() { Form1 obj = null; XmlSerializer mySerializer = new XmlSerializer(typeof(Form1)); FileStream myFileStream = new FileStream("C:\\myDrawing.xml", FileMode.Open); obj= (Form1)mySerializer.Deserialize(myFileStream); obj.Draw(); } private void Form2_Load(object sender, EventArgs e) { Serialize(); // Form1 f = new Form1(); // putIt objDele = new putIt(f.toi); //objDele(); } private void button1_Click(object sender, EventArgs e) { DeSerialize(); } } now i think its enough for understanding ?
hghghgh
Your code shows nothing related to an image, and as the others stated, you'll need to create an image to serialize (although your question is really hard to understand). System.Drawing.Image is serializable = here's a simple example:
Bitmap bm = new Bitmap(320, 240, PixelFormat.Format24bppRgb);
Graphics g = Graphics.FromImage(bm);
Pen pen = new Pen(Color.Azure);
g.DrawEllipse(pen, 10, 10, 100, 100);
g.DrawRectangle(pen, 10, 10, 200, 200);
//FileStream fs = new FileStream("c:\\serialized_bitmap.soap", FileMode.Create);
FileStream fs = new FileStream("c:\\serialized_bitmap.dat", FileMode.Create);
//SoapFormatter formatter = new SoapFormatter();
BinaryFormatter formatter = new BinaryFormatter();
try
{
formatter.Serialize(fs, bm);
}
catch (SerializationException )//e)
{
//Console::WriteLine( "Failed to serialize. Reason: {0}", e->Message );
throw;
}
finally
{
fs.Close();
}Of course, you'll have to create your Image/Bitmap the way you need to.
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
Your code shows nothing related to an image, and as the others stated, you'll need to create an image to serialize (although your question is really hard to understand). System.Drawing.Image is serializable = here's a simple example:
Bitmap bm = new Bitmap(320, 240, PixelFormat.Format24bppRgb);
Graphics g = Graphics.FromImage(bm);
Pen pen = new Pen(Color.Azure);
g.DrawEllipse(pen, 10, 10, 100, 100);
g.DrawRectangle(pen, 10, 10, 200, 200);
//FileStream fs = new FileStream("c:\\serialized_bitmap.soap", FileMode.Create);
FileStream fs = new FileStream("c:\\serialized_bitmap.dat", FileMode.Create);
//SoapFormatter formatter = new SoapFormatter();
BinaryFormatter formatter = new BinaryFormatter();
try
{
formatter.Serialize(fs, bm);
}
catch (SerializationException )//e)
{
//Console::WriteLine( "Failed to serialize. Reason: {0}", e->Message );
throw;
}
finally
{
fs.Close();
}Of course, you'll have to create your Image/Bitmap the way you need to.
Mark Salsbery Microsoft MVP - Visual C++ :java: