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

如何动态给picturebox控件的size属性赋值
如题,我有一批图片,分辨率不一,我把这些图片显示在flawlayoutpanel中的picturebox控件上了,当我点击某个picturebox控件时,我给当前点击的图片加载到我窗体左侧的panel中的picturebox控件上,因为我flawlayoutpanel中picturebox控件上的图片大小不一样,所以我想动态的给panel中的picturebox控件的size赋值,让他按比例显示(我的左侧的picturebox控件支持放大缩小左转右转(左转右转改变原图)),现在只有按比例显示没做出来了,求高手解答????

------解决方案--------------------
/// <summary> 
        /// 对给定的一个图片(Image对象)生成一个指定大小的缩略图。 
        /// </summary> 
        /// <param name="originalImage">原始图片</param> 
        /// <param name="thumMaxWidth">缩略图的宽度</param> 
        /// <param name="thumMaxHeight">缩略图的高度</param> 
        /// <returns>返回缩略图的Image对象</returns> 
        public static System.Drawing.Image GetThumbNailImage(System.Drawing.Image originalImage, int thumMaxWidth, int thumMaxHeight)
        {
            Size thumRealSize = Size.Empty;
            System.Drawing.Image newImage = originalImage;
            Graphics graphics = null;

            try
            {
                thumRealSize = GetNewSize(thumMaxWidth, thumMaxHeight, originalImage.Width, originalImage.Height);
                newImage = new Bitmap(thumRealSize.Width, thumRealSize.Height);
                graphics = Graphics.FromImage(newImage);

                graphics.CompositingQuality = CompositingQuality.HighQuality;