コード例 #1
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
                   );
     }
 }
コード例 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="source_bitmap"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <returns></returns>
        public static Bitmap GetBitmapThumbnail(Bitmap source_bitmap, int thumbnail_dimension, DimensionType apply_to)
        {
            float bitmap_width  = (float)source_bitmap.Width;
            float bitmap_height = (float)source_bitmap.Height;

            float thumbnail_width  = 0f;
            float thumbnail_height = 0f;

            if (apply_to == DimensionType.Height)
            {
                thumbnail_height = thumbnail_dimension;
                thumbnail_width  = bitmap_width * thumbnail_height / bitmap_height;
            }
            else
            {
                thumbnail_width  = thumbnail_dimension;
                thumbnail_height = bitmap_height * thumbnail_width / bitmap_width;
            }
            return(BitmapTools.Resize(source_bitmap, thumbnail_width, thumbnail_height));
        }