private void doOpenFile(bool tryReadStrokes, bool removeColors) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "Images|*.jpg;*.bmp;*.png;*.jpeg"; if (ofd.ShowDialog() == DialogResult.OK) { Bitmap bmpSrc = new Bitmap(ofd.FileName); curFile = ofd.FileName; //DynamicShadingCPU.EqualizeHistogram(bmpSrc); #region base64 example //MemoryStream stream = new MemoryStream(); //bmpSrc.Save(stream, System.Drawing.Imaging.ImageFormat.Png); //byte[] imageBytes = stream.ToArray(); //// Convert byte[] to Base64 String //string base64String = Convert.ToBase64String(imageBytes); //byte[] b2 = Convert.FromBase64String(base64String); //MemoryStream ms2 = new MemoryStream(b2); //bmpSrc = new Bitmap(ms2); #endregion if (removeColors) { DynamicShadingCPU.RemoveColors(bmpSrc, 33); } List <DynamicShadingCPU.ColorStroke> strokes = null; if (tryReadStrokes) { strokes = DynamicShadingCPU.GetColorStrokes(bmpSrc, 33); } float thresh = DynamicShadingCPU.getOtsuThreshold(bmpSrc); List <int> edges = DynamicShadingCPU.RetrieveImageEdges(bmpSrc, thresh); lblStatus.Text = "Otsu threshold: " + thresh.ToString(); picShadeImg.Image = DynamicShadingCPU.RetrieveImageFromEdges(edges, bmpSrc.Width, bmpSrc.Height); ds = new DynamicShadingCPU(edges, bmpSrc.Width, bmpSrc.Height); if (File.Exists(ofd.FileName + ".json")) { ds = DynamicShadingCPU.FromJson(ofd.FileName + ".json"); } else if (File.Exists(ofd.FileName + ".strokes")) { ds.LoadStrokes(ofd.FileName + ".strokes"); } else if (tryReadStrokes) { ds._strokes = strokes; } picShadeImg.Invalidate(); } }
private void revertToOriginalToolStripMenuItem_Click(object sender, EventArgs e) { picShadeImg.Image = DynamicShadingCPU.RetrieveImageFromEdges(ds._edges, ds.ImageWidth, ds.ImageHeight); picShadeImg.Invalidate(); }