public Bitmap GetBitmap() { uEye.Defines.Status statusRet = 0; // Get last image memory Int32 s32LastMemId; Int32 s32Width; Int32 s32Height; statusRet = m_Camera.Memory.GetLast(out s32LastMemId); statusRet = m_Camera.Memory.Lock(s32LastMemId); statusRet = m_Camera.Memory.GetSize(s32LastMemId, out s32Width, out s32Height); Bitmap MyBitmap; statusRet = m_Camera.Memory.ToBitmap(s32LastMemId, out MyBitmap); // clone bitmap Rectangle cloneRect = new Rectangle(0, 0, s32Width, s32Height); System.Drawing.Imaging.PixelFormat format = System.Drawing.Imaging.PixelFormat.Format32bppArgb; Bitmap cloneBitmap = MyBitmap.Clone(cloneRect, format); // unlock image buffer statusRet = m_Camera.Memory.Unlock(s32LastMemId); MyBitmap.Dispose(); return(cloneBitmap); }
/// <summary> /// The Function Adds A file in the appropriate place in the file system /// also creates a thumbnail in the appropriate place /// </summary> /// <param name="path">The Path of the Image from the file</param> /// <returns>Indication if the Addition Was Successful</returns> public string AddFile(string path, out bool Result) { Result = false; //first check if file exists try { if (!System.IO.File.Exists(path)) { Result = false; return("AddFile error: File does not exist."); } // top-level folder name. string OutputPath = ConfigurationManager.AppSettings["OutputDir"]; //get file name to update path for copying string FileName = System.IO.Path.GetFileName(path); //thumbnail creation// int ThumbSize = Int32.Parse(ConfigurationManager.AppSettings["ThumbnailSize"]); Thread.Sleep(1000); System.IO.FileStream Stream = new FileStream(path, FileMode.Open); DateTime Date; try { //try to get the date the image was taken on. PropertyItem PropItem = Image.FromStream(Stream, false, false).GetPropertyItem(36867); Regex RegularExpression = new Regex(":"); string dateTaken = RegularExpression.Replace(Encoding.UTF8.GetString(PropItem.Value), "-", 2); Date = DateTime.Parse(dateTaken); } catch { //If the date could not be recovered or does not exist, //use the file creation date instead Date = System.IO.File.GetCreationTime(path); } //parse date into path for a new folder //string Time = Date.Year.ToString() + @"\" + Date.Month.ToString(); string Time = System.IO.Path.Combine(Date.Year.ToString(), Date.Month.ToString()); Bitmap MyBitmap; try { MyBitmap = (Bitmap)Image.FromStream(Stream); } catch (Exception e) { return("Error: " + e.ToString() + "\n" + e.StackTrace.ToString() + "\n" + e.HelpLink); } Image MyThumbnail = MyBitmap.GetThumbnailImage(ThumbSize, ThumbSize, () => false, IntPtr.Zero); string TargetThumb = System.IO.Path.Combine(OutputPath, "Thumbnails"); TargetThumb = System.IO.Path.Combine(TargetThumb, Time); if (!System.IO.Directory.Exists(TargetThumb)) { System.IO.Directory.CreateDirectory(TargetThumb); } MyThumbnail.Save(Path.Combine(TargetThumb, FileName)); //pic creation// string TargetFile = System.IO.Path.Combine(OutputPath, Time); if (!System.IO.Directory.Exists(TargetFile)) { System.IO.Directory.CreateDirectory(TargetFile); DirectoryInfo di = new DirectoryInfo(TargetFile); //See if directory has hidden flag, if not, make hidden if ((di.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden) { //Add Hidden flag di.Attributes |= FileAttributes.Hidden; } } TargetFile = System.IO.Path.Combine(TargetFile, FileName); System.IO.File.Copy(path, TargetFile); MyBitmap.Dispose(); MyThumbnail.Dispose(); Stream.Flush(); Stream.Close(); Result = true; return(System.IO.Path.Combine(OutputPath, FileName));; } catch (Exception e) { return("Error: " + e.ToString() + "\n" + e.StackTrace.ToString() + "\n" + e.HelpLink); } }