Esempio n. 1
0
        /// <summary>
        /// A simple scaling routine
        /// </summary>
        /// <param name="bitmap">Bitmap to scale</param>
        /// <param name="dpi">uint with the dpi value to scale for</param>
        /// <returns>Bitmap</returns>
        public static Bitmap SimpleBitmapScaler(Bitmap bitmap, uint dpi)
        {
            if (dpi == DpiHandler.DefaultScreenDpi)
            {
                return(bitmap);
            }

            var newSize = DpiHandler.ScaleWithDpi(bitmap.Size, dpi);
            var result  = new Bitmap(newSize.Width, newSize.Height, bitmap.PixelFormat);

            using (var graphics = Graphics.FromImage(result))
            {
                graphics.InterpolationMode = InterpolationMode.NearestNeighbor;
                graphics.DrawImage(bitmap, new Rectangle(0, 0, newSize.Width, newSize.Height), new Rectangle(0, 0, bitmap.Width, bitmap.Height), GraphicsUnit.Pixel);
            }
            return(result);
        }
Esempio n. 2
0
        /// <summary>
        ///     Create a BitmapScaleHandler with a ComponentResourceManager as resource provider
        /// </summary>
        /// <param name="dpiHandler">DpiHandler</param>
        /// <param name="resourceType">Type to create the ComponentResourceManager for</param>
        /// <param name="bitmapScaler">A function to provide a newly scaled bitmap, you can return the provide bitmap if you want to keep it as is</param>
        public static BitmapScaleHandler <string> WithComponentResourceManager(DpiHandler dpiHandler, Type resourceType, Func <Bitmap, uint, Bitmap> bitmapScaler = null)
        {
            var resources = new ComponentResourceManager(resourceType);

            return(Create <string>(dpiHandler, (imageName, dpi) => (Bitmap)resources.GetObject(imageName), bitmapScaler));
        }
 /// <summary>
 ///     Create a BitmapScaleHandler with a ComponentResourceManager as resource provider
 /// </summary>
 /// <param name="dpiHandler">DpiHandler</param>
 /// <param name="resourceType">Type to create the ComponentResourceManager for</param>
 /// <param name="bitmapScaler">A function to provide a newly scaled bitmap, you can return the provide bitmap if you want to keep it as is</param>
 public static BitmapScaleHandler <string, TValue> WithComponentResourceManager <TValue>(DpiHandler dpiHandler, Type resourceType, Func <TValue, uint, TValue> bitmapScaler = null) where TValue : IDisposable
 {
     return(Create <string, TValue>(dpiHandler, (imageName, dpi) =>
     {
         var resources = new ComponentResourceManager(resourceType);
         return (TValue)resources.GetObject(imageName);
     }, bitmapScaler));
 }