tangxu
2024-12-16 23fadc9cb0c09b665a1bbcef7eaf16f916045dc4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#region Imports
 
using System;
using System.Drawing;
 
#endregion
 
namespace DPumpHydr.WinFrmUI.RLT.Extension.Poison
{
    #region PoisonImageExtension
 
    internal class PoisonImage
    {
        public static Image ResizeImage(Image imgToResize, Rectangle maxOffset)
        {
            int sourceWidth = imgToResize.Width;
            int sourceHeight = imgToResize.Height;
 
            float nPercent = 0;
            float nPercentW = 0;
            float nPercentH = 0;
 
            nPercentW = (float)maxOffset.Width / sourceWidth;
            nPercentH = (float)maxOffset.Height / sourceHeight;
 
            nPercent = nPercentH < nPercentW ? nPercentH : nPercentW;
 
            int destWidth = (int)(sourceWidth * nPercent);
            int destHeight = (int)(sourceHeight * nPercent);
 
            return imgToResize.GetThumbnailImage(destWidth, destHeight, null, IntPtr.Zero);
        }
    }
 
    #endregion
}