/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object can be used to retrieve data from input parameters and /// to store data in output parameters.</param> protected override void SolveInstance(IGH_DataAccess DA) { string bmpAPath = null; string bmpBPath = null; if (!DA.GetData(0, ref bmpAPath)) { return; } if (!DA.GetData(0, ref bmpBPath)) { return; } if (bmpAPath == null | bmpAPath.Length == 0) { return; } if (bmpBPath == null | bmpBPath.Length == 0) { return; } var bmpA = (Bitmap)Image.FromFile(bmpAPath, true); var bmpB = (Bitmap)Image.FromFile(bmpBPath, true); var stitcher = new StitcherClass(bmpA, bmpB, true); Bitmap complete = stitcher.CompleteImage; var dir = System.IO.Directory.GetParent(bmpAPath); // Write out the complete bitmap string outputFileName = dir + "_Stitched" + ".jpg"; using (MemoryStream memory = new MemoryStream()) { using (FileStream fs = new FileStream(outputFileName, FileMode.Create, FileAccess.ReadWrite)) { complete.Save(memory, System.Drawing.Imaging.ImageFormat.Jpeg); byte[] bytes = memory.ToArray(); fs.Write(bytes, 0, bytes.Length); } } //stitcher.Dispose(); DA.SetData(0, outputFileName); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object can be used to retrieve data from input parameters and /// to store data in output parameters.</param> protected override void SolveInstance(IGH_DataAccess DA) { string bmpDirPath = null; // Defence //if (!DA.GetData(0, ref data)) { return; } //if (data == null) { return; } //if (data.Length == 0) { return; } bmpDirPath = @"C:\Users\Leland Jobson\AppData\Roaming\aviary"; var myFiles = new DirectoryInfo(bmpDirPath).GetFiles() .OrderBy(f => f.LastWriteTime) .ToList(); List <string> myFileNames = new List <string>(); foreach (var fi in myFiles) { myFileNames.Add(fi.FullName); } Bitmap memBit = null; string memName = ""; for (int i = 1; i < myFiles.Count; i++) { if (memBit == null) { memName = myFiles[i - 1].FullName; memBit = (Bitmap)Image.FromFile(memName, true); } Bitmap image2 = (Bitmap)Image.FromFile(myFiles[i].FullName, true); try { var stitcher = new StitcherClass(memBit, image2); memBit = stitcher.CompleteImage; string img2Name = myFiles[i].FullName; // Write out the progress bitmap string progressFileName = memName + "_StitchedTo_" + img2Name + ".jpg"; using (MemoryStream memory = new MemoryStream()) { using (FileStream fs = new FileStream(progressFileName, FileMode.Create, FileAccess.ReadWrite)) { memBit.Save(memory, System.Drawing.Imaging.ImageFormat.Jpeg); byte[] bytes = memory.ToArray(); fs.Write(bytes, 0, bytes.Length); } } // Update the progress file name string memName = myFiles[i].FullName; image2.Dispose(); } catch (Exception e) { // Stop stitching and return however far you got. image2.Dispose(); continue; } } // Write out the complete bitmap string outputFileName = bmpDirPath + "_Stitched" + ".jpg"; using (MemoryStream memory = new MemoryStream()) { using (FileStream fs = new FileStream(outputFileName, FileMode.Create, FileAccess.ReadWrite)) { memBit.Save(memory, System.Drawing.Imaging.ImageFormat.Jpeg); byte[] bytes = memory.ToArray(); fs.Write(bytes, 0, bytes.Length); } } memBit.Dispose(); DA.SetData(0, outputFileName); }