/[gr2lib]/trunk/gr2lib/core/ui/typeeditors/HexEditor.cs
ViewVC logotype

Diff of /trunk/gr2lib/core/ui/typeeditors/HexEditor.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/gr2lib/core/ui/typeeditors/HexEditor.cs	2010/07/23 17:18:46	175
+++ trunk/gr2lib/core/ui/typeeditors/HexEditor.cs	2010/07/23 18:57:45	176
@@ -8,6 +8,8 @@
 using System.Windows.Forms;
 using gr2lib.core.ui.rigeditor.interfaces;
 using Be.Windows.Forms;
+using System.IO;
+using gr2lib.core.coretypes.implementation;
 
 namespace gr2lib.core.ui.typeeditors
 {
@@ -70,5 +72,54 @@
             }
         }
 
+        private void btnImport_Click(object sender, EventArgs e)
+        {
+            //throw new NotImplementedException("Import Has Not Been Implemented");
+            DialogResult result = PixelImporter.ShowDialog();
+            if (result != DialogResult.OK) return;
+
+            // read bytes from file
+            FileStream fs = new FileStream(PixelImporter.FileName, FileMode.Open);
+            List<byte> _pixels = new List<byte>();
+            BinaryReader r = new BinaryReader(fs);
+            r.BaseStream.Seek(0, SeekOrigin.Begin);
+            byte[] bytes = r.ReadBytes((int)r.BaseStream.Length);
+            r.Close();
+
+            foreach (byte b in bytes)
+            {
+                _pixels.Add(b);
+            }            
+
+            MessageBox.Show("Successfully imported: " + _pixels.Count + " (" + string.Format("0x{0}", _pixels.Count.ToString("X8")) + ")" + " pixel bytes", "Pixel Data Import Successfull!", MessageBoxButtons.OK, MessageBoxIcon.Information);
+            this.AsBytes = _pixels.ToArray();
+
+        }
+
+        private void btnExport_Click(object sender, EventArgs e)
+        {
+            //throw new NotImplementedException("Export Has Not Been Implemented");
+            DialogResult result = PixelExporter.ShowDialog();
+            if (result != DialogResult.OK) return;
+
+            try
+            {
+                FileStream fs = new FileStream(PixelExporter.FileName, FileMode.Create);
+                BinaryWriter w = new BinaryWriter(fs);
+                foreach (byte b in Value.ToArray())
+                {
+                    w.Write(b);
+                }
+                w.Flush();
+                w.Close();
+                MessageBox.Show("Successfully exported: " + Value.Count + " (" + string.Format("0x{0}", Value.Count.ToString("X8")) + ")" + " pixel bytes", "Pixel Data Export Successfull!", MessageBoxButtons.OK, MessageBoxIcon.Information);
+            }
+            catch (Exception ex)
+            {
+                MessageBox.Show("Failed to export pixel data!\n\nMessage: " + ex.Message, "Pixel Data Export Failed!", MessageBoxButtons.OK, MessageBoxIcon.Error);
+                return;
+            }
+        }
+
     }
 }

 

  ViewVC Help
Powered by ViewVC 1.1.22