日期:2014-05-17  浏览次数:21119 次

ImageList如何保持图片比例显示?
如:原图片大小:200*160,ImageList的size大小为:100*100。


最终显示出来的图片希望显示为:100*80,并居中显示。

即图片按照比例缩小并显示。

请问有什么好办法?

------解决方案--------------------
我都是缩放好了再放进去
特别是遇到比ImageList小的图片,
放进去被放大后真是惨不忍睹
------解决方案--------------------
C# code
  
图片等比缩放,不会失真,设置picturebox控件的sizemode属性为CenterImage 居中显示

    public static Image GetPicBySize(Image image, int width, int height)
        {
            int picWidth = image.Width;
            int picHeight = image.Height;

            if (picWidth < width && picHeight < width)
            {
                width = picWidth;
                height = picHeight;
            }
            else if (picWidth / picHeight > width / height)
            {
                height = width * picHeight / picWidth;
            }
            else
            {
                width = height * picWidth / picHeight;
            }

            Bitmap thumb = new Bitmap(width, height);
            using (Graphics g_thumb = Graphics.FromImage(thumb))
            {
                g_thumb.InterpolationMode = InterpolationMode.HighQualityBicubic;
                g_thumb.DrawImage(image, 0, 0, width, height);
            }
            return (Image)thumb;
        }