Ejemplo n.º 1
0
        /// <summary>
        /// Captures an image from a video
        /// </summary>
        /// <param name="source_video">FileInfo contia</param>
        /// <param name="capture_time">Time in seconds at which you want to capture the image</param>
        /// <param name="sleep_time">Time in milliseconds to sleep so that MediaPlayer doesn't crap itself</param>
        /// <returns>A System.Drawing.Bitmap captured from the video</returns>
        public static Bitmap Capture(FileInfo source_video, double capture_time, int sleep_time)
        {
            try
            {
                MediaPlayer   paused_video           = InternalTools.GetPausedVideo(source_video.FullName, capture_time, sleep_time);
                BitmapFrame   image_data_at_position = InternalTools.GetVideoImageData(paused_video);
                BitmapEncoder image_data_encoder     = InternalTools.GetImageDataEncoder(image_data_at_position);
                Bitmap        captured_bitmap;

                using (MemoryStream stream = new MemoryStream())
                {
                    image_data_encoder.Frames.Add(image_data_at_position);
                    image_data_encoder.Save(stream);
                    byte[] bit = stream.ToArray();
                    captured_bitmap = Bitmap.FromStream(stream) as Bitmap;
                    stream.Close();
                }
                return(captured_bitmap);
            }
            catch (Exception e)
            {
                throw new ImagingTools.MediaToolsGenericException(
                          "Capture_Bitmap.Capture(FileInfo source_video, double capture_time, int sleep_time)",
                          e
                          );
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Scale a bitmap to a max dimension, maintaining the original aspect ratio
 /// </summary>
 /// <param name="source_bitmap"></param>
 /// <param name="max_dimension_value"></param>
 /// <returns>Scaled System.Drawing.Bitmap</returns>
 public static Bitmap Scale(Bitmap source_bitmap, int max_dimension_value)
 {
     try
     {
         System.Drawing.Size new_size = InternalTools.GetScaledSize(source_bitmap, max_dimension_value);
         return(BitmapTools.Resize(source_bitmap, new_size.Width, new_size.Height));
     }
     catch (Exception e)
     {
         throw new ImagingTools.MediaToolsGenericException(
                   "Save_Bitmap.Save(Bitmap source_bitmap, FileInfo saved_bitmap_file_info)",
                   e
                   );
     }
 }
Ejemplo n.º 3
0
        public static float GetDerivedDimension(
            float constant_value,
            float max_dimension_value,
            float derived_value
            )
        {
            ResizeType resize_type = InternalTools.GetResizeType(
                (int)constant_value,
                (int)max_dimension_value
                );
            float multiplier = 0f;

            if (resize_type == ResizeType.Reduction)
            {
                multiplier = max_dimension_value / constant_value;
            }
            else
            {
                multiplier = constant_value / max_dimension_value;
            }
            return(derived_value * multiplier);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Make a grayscale copy of the bitmap
        /// </summary>
        /// <param name="source_bitmap">The System.Drawing.Bitmap you want to convert</param>
        /// <returns>Grayscale copy of the original bitmap</returns>
        public static Bitmap Desaturate(Bitmap source_bitmap)
        {
            try
            {
                Rectangle source_rectangle = new Rectangle(0, 0, source_bitmap.Width, source_bitmap.Height);
                //create a blank bitmap the same size as original
                Bitmap   desaturated_bitmap = new Bitmap(source_bitmap.Width, source_bitmap.Height);
                Graphics g = Graphics.FromImage(desaturated_bitmap);

                ImageAttributes desaturated_bitmap_attributes = new ImageAttributes();
                desaturated_bitmap_attributes.SetColorMatrix(InternalTools.GetGrayscaleMatrix());

                //draw the original image on the new image
                //using the grayscale color matrix
                g.DrawImage(
                    source_bitmap,
                    source_rectangle,
                    0,
                    0,
                    source_bitmap.Width,
                    source_bitmap.Height,
                    GraphicsUnit.Pixel,
                    desaturated_bitmap_attributes
                    );

                //dispose the Graphics object
                g.Dispose();
                return(desaturated_bitmap);
            }
            catch (Exception e)
            {
                throw new ImagingTools.MediaToolsGenericException(
                          "Save_Bitmap.Save(Bitmap source_bitmap, FileInfo saved_bitmap_file_info)",
                          e
                          );
            }
        }