Beispiel #1
0
        /// <summary>
        /// Computes size of the auto-sized image
        /// </summary>
        /// <param name="imageSize"></param>
        /// <param name="imageRect"></param>
        /// <param name="windowRect"></param>
        /// <param name="srcRect"></param>
        /// <returns></returns>
        public static Rectangle ComputeImageSize(AutoImageSize imgSize, Rectangle imgRect, Rectangle wndRect)
        {
            float imgAspect = ((float)imgRect.Height) / (float)imgRect.Width;
            float wndAspect = ((float)wndRect.Height) / (float)wndRect.Width;

            if ((imgSize == AutoImageSize.Stretch) && (imgAspect > wndAspect))
            {
                int h = wndRect.Height;
                int y = wndRect.Y;
                int w = (int)(wndRect.Height / imgAspect);
                int x = wndRect.X + (wndRect.Width - w) / 2;

                return(new Rectangle(x, y, w + x, y + h));
            }

            if ((imgSize == AutoImageSize.FitWidth) || ((imgSize == AutoImageSize.Stretch) && (imgAspect <= wndAspect)))
            {
                int x = wndRect.X;
                int w = wndRect.Width;
                int h = (int)(imgAspect * wndRect.Width);
                int y = wndRect.Y + (wndRect.Height - h) / 2;

                return(new Rectangle(x, y, w + x, y + h));
            }
            return(wndRect);
        }
Beispiel #2
0
		/// <summary>
		/// Computes size of the auto-sized image
		/// </summary>
		/// <param name="imageSize"></param>
		/// <param name="imageRect"></param>
		/// <param name="windowRect"></param>
		/// <param name="srcRect"></param>
		/// <returns></returns>
		public static Rectangle ComputeImageSize ( AutoImageSize imgSize, Rectangle imgRect, Rectangle wndRect )
		{
			float imgAspect	= ((float)imgRect.Height) / (float)imgRect.Width;
			float wndAspect	= ((float)wndRect.Height) / (float)wndRect.Width;

			if( ( imgSize == AutoImageSize.Stretch ) && ( imgAspect > wndAspect ) ) {
				int h  = wndRect.Height;
				int y  = wndRect.Y;
				int w  = (int)( wndRect.Height / imgAspect );
				int x  = wndRect.X + ( wndRect.Width - w ) / 2;

				return new Rectangle( x, y, w + x, y + h );
			}

			if( ( imgSize == AutoImageSize.FitWidth ) || ( ( imgSize == AutoImageSize.Stretch ) && ( imgAspect <= wndAspect ) ) ) {
				int x = wndRect.X;
				int w = wndRect.Width;
				int h = (int)( imgAspect * wndRect.Width );
				int y = wndRect.Y + ( wndRect.Height - h ) / 2;

				return new Rectangle( x, y, w + x, y + h );
			}
			return wndRect;
		}