// This method takes a PcImage and a desired file path and name, then creates a bitmap of it, and saves. Once // more, like all methods in the ToolBox class, these are simply time-saving methods. Use at your own discretion. public static void SaveProcessedImage(PcImage image, string filePathAndName) { using (Bitmap bmp = ToolBox.CreateBitmap(image, true)) { bmp.Save(filePathAndName); } }
public static Bitmap createBitmap(PcImage pcImage) { Bitmap bmp; switch (pcImage.PixelFormat) { case PcPixelFormat.BGR: bmp = new Bitmap(pcImage.Size.Width, pcImage.Size.Height, pcImage.RowSize, PixelFormat.Format24bppRgb, pcImage.BufferHandle); break; case PcPixelFormat.BGRA: bmp = new Bitmap(pcImage.Size.Width, pcImage.Size.Height, pcImage.RowSize, PixelFormat.Format32bppArgb, pcImage.BufferHandle); break; case PcPixelFormat.Grayscale: bmp = new Bitmap(pcImage.Size.Width, pcImage.Size.Height, pcImage.RowSize, PixelFormat.Format16bppGrayScale, pcImage.BufferHandle); break; case PcPixelFormat.Grayscale16: bmp = new Bitmap(pcImage.Size.Width, pcImage.Size.Height, pcImage.RowSize, PixelFormat.Format16bppGrayScale, pcImage.BufferHandle); break; default: bmp = new Bitmap(pcImage.Size.Width, pcImage.Size.Height, pcImage.RowSize, PixelFormat.DontCare, pcImage.BufferHandle); break; } return(bmp); }
// This saves the parent-level image of IPcPicture. public static void SaveMatImage(IPcPicture picture) { _saveDirectory = Path.Combine(ToolBox.defaultFilePath, @"Pictures\" + DateTime.Now.ToString("MM-dd-yyyy_hh.mm.ss" + "_" + marker)); ToolBox.EnsureDirectoryExists(_saveDirectory); PcImage image = picture.Image; string fileAndPath = Path.Combine(_saveDirectory, "MatImage.bmp"); ToolBox.SaveProcessedImage(image, fileAndPath); marker++; }
// Saves the outlines public static OutlineParameters SavePicture(IPcPicture picture, IPcOutline parentOutline) { _saveDirectory = Path.Combine(ToolBox.defaultFilePath, @"Pictures\" + "ConfirmDirectory"); ToolBox.EnsureDirectoryExists(_saveDirectory); ToolBox.EnsureDirectoryExists(ToolBox.defaultFilePath); PcImage image = picture.Image; confirmPath = Path.Combine(_saveDirectory, "confirmPicture" + marker2 + ".bmp"); ToolBox.SaveProcessedImage(image, confirmPath); marker2++; List <Point> outlineBoundaries = new List <Point>(); Point globalPicSize = new Point(Convert.ToInt32(GetOutlineWidth(parentOutline)), Convert.ToInt32(GetOutlineHeight(parentOutline))); foreach (IPcOutline outline in parentOutline.Children) { if (GetOutlineHeight(outline) > 50 && GetOutlineWidth(outline) > 50) { outlineBoundaries.Add(new Point(Convert.ToInt32(GetOutlineWidth(outline)), Convert.ToInt32(GetOutlineHeight(outline)))); } } List <PcPhysicalPoint> pictureLocation = new List <PcPhysicalPoint>(); foreach (IPcPicture pic in picture.Children) { PcPhysicalPoint loc = new PcPhysicalPoint(pic.PhysicalBoundaries.Location.X * (pic.PixelDensity.X), pic.PhysicalBoundaries.Location.Y * (pic.PixelDensity.Y)); pictureLocation.Add(loc); } OutlineParameters op = new OutlineParameters(pictureLocation, outlineBoundaries, globalPicSize); return(op); }