Beispiel #1
0
        private void LoadSerializedObj(MySerializeObj obj)
        {
            Size size = obj.GetSize();

            CreateMainPaint(size.Width, size.Height);
            LoadLayersFromSerializedObj(obj);
        }
Beispiel #2
0
        private void toolStrip_Save_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveDialog = new SaveFileDialog();

            saveDialog.Filter = "PaintYourLife Files|*.pyl|Image Files|*.png; *.jpg; *.jpeg;...";

            if (mainDrawingPicture.Visible && saveDialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if (listView_layer.SelectedItems.Count > 0)
                    {
                        Layer layer = listView_layer.SelectedItems[0].Tag as Layer;
                        layer.ChangeSelection(false);
                    }

                    ReDraw();
                    string a = Path.GetExtension(saveDialog.FileName);
                    switch (a.ToLower())
                    {
                    case ".bmp":
                        mainDrawingBitmap.Save(saveDialog.FileName, System.Drawing.Imaging.ImageFormat.Bmp);
                        break;

                    case ".png":
                        mainDrawingBitmap.Save(saveDialog.FileName, System.Drawing.Imaging.ImageFormat.Png);
                        break;

                    case ".jpg":
                    case ".jpeg":
                        mainDrawingBitmap.Save(saveDialog.FileName, System.Drawing.Imaging.ImageFormat.Jpeg);
                        break;

                    case ".gif":
                        mainDrawingBitmap.Save(saveDialog.FileName, System.Drawing.Imaging.ImageFormat.Gif);
                        break;

                    case ".pyl":
                        IFormatter formatter = new BinaryFormatter();
                        Stream     stream    = new FileStream(saveDialog.FileName,
                                                              FileMode.Create,
                                                              FileAccess.Write, FileShare.None);
                        MySerializeObj obj = new MySerializeObj(this);
                        formatter.Serialize(stream, obj);

                        stream.Close();
                        break;

                    default: throw new Exception("Cannot save your life !!!");
                    }
                    MessageBox.Show("Saving your life successfully");
                }
                catch (Exception error) { MessageBox.Show(error.Message); }
            }
        }
Beispiel #3
0
        private void OpenPYLFile(string dir)
        {
            IFormatter formatter = new BinaryFormatter();
            Stream     stream    = new FileStream(dir,
                                                  FileMode.Open,
                                                  FileAccess.Read,
                                                  FileShare.Read);

            MySerializeObj obj = formatter.Deserialize(stream) as MySerializeObj;

            LoadSerializedObj(obj);
            stream.Close();
        }
Beispiel #4
0
        private void LoadLayersFromSerializedObj(MySerializeObj obj)
        {
            listView_layer.Clear();
            List <Layer> layer = obj.GetLayer();

            counterShape = obj.GetCounter();

            foreach (Layer l in layer)
            {
                ListViewItem item = new ListViewItem(l.GetName());
                item.Tag = l;
                listView_layer.Items.Add(item);
            }

            previousIndex = obj.GetPreviousIndex();

            ReDraw();
        }