none
定点放大缩小图片思路或代码 RRS feed

答案

  • 使用两种方式都可以的,建议最好使用DrawImage的方式来实现,具体代码可以参考这个博客:

    http://www.cnblogs.com/fengzhifengyi/archive/2011/05/12/2044224.html

    /// <summary> 
        /// 放大缩小图片尺寸 
        /// </summary> 
        /// <param name="picPath"></param> 
        /// <param name="reSizePicPath"></param> 
        /// <param name="iSize"></param> 
        /// <param name="format"></param> 
        public void PicSized(string picPath, string reSizePicPath, int iSize, ImageFormat format) 
        { 
            Bitmap originBmp = new Bitmap(picPath); 
            int w = originBmp.Width * iSize; 
            int h = originBmp.Height * iSize; 
            Bitmap resizedBmp = new Bitmap(w, h); 
            Graphics g = Graphics.FromImage(resizedBmp); 
            //设置高质量插值法   
            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; 
            //设置高质量,低速度呈现平滑程度   
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; 
            g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; 
            //消除锯齿 
            g.SmoothingMode = SmoothingMode.AntiAlias; 
            g.DrawImage(originBmp, new Rectangle(0, 0, w, h), new Rectangle(0, 0, originBmp.Width, originBmp.Height), GraphicsUnit.Pixel); 
            resizedBmp.Save(reSizePicPath, format); 
            g.Dispose(); 
            resizedBmp.Dispose(); 
            originBmp.Dispose(); 
        }


    If my post is helpful,please help to vote as helpful, if my post solve your question, please help to make it as answer. my sample

    2013年6月12日 11:17

全部回复

  • 你好,能提供更多关于你问题的信息吗? 你想实现怎样的效果的?还有是什么项目类型,例如是WinForm还是Asp.Net?

    If my post is helpful,please help to vote as helpful, if my post solve your question, please help to make it as answer. my sample

    2013年6月2日 12:41
  • cad在想做的一个透明图片上蒙cad图,cad上的放大是框式,透明图平移后应以定点为中心放大才好校正已再次放大的cad。需c#winfom代码  用DramImage()做放大,还是宽高乘一个数,一般哪种方法用适合又静准



    • 已编辑 yinlin88 2013年6月2日 15:11
    2013年6月2日 14:49
  • 使用两种方式都可以的,建议最好使用DrawImage的方式来实现,具体代码可以参考这个博客:

    http://www.cnblogs.com/fengzhifengyi/archive/2011/05/12/2044224.html

    /// <summary> 
        /// 放大缩小图片尺寸 
        /// </summary> 
        /// <param name="picPath"></param> 
        /// <param name="reSizePicPath"></param> 
        /// <param name="iSize"></param> 
        /// <param name="format"></param> 
        public void PicSized(string picPath, string reSizePicPath, int iSize, ImageFormat format) 
        { 
            Bitmap originBmp = new Bitmap(picPath); 
            int w = originBmp.Width * iSize; 
            int h = originBmp.Height * iSize; 
            Bitmap resizedBmp = new Bitmap(w, h); 
            Graphics g = Graphics.FromImage(resizedBmp); 
            //设置高质量插值法   
            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; 
            //设置高质量,低速度呈现平滑程度   
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; 
            g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; 
            //消除锯齿 
            g.SmoothingMode = SmoothingMode.AntiAlias; 
            g.DrawImage(originBmp, new Rectangle(0, 0, w, h), new Rectangle(0, 0, originBmp.Width, originBmp.Height), GraphicsUnit.Pixel); 
            resizedBmp.Save(reSizePicPath, format); 
            g.Dispose(); 
            resizedBmp.Dispose(); 
            originBmp.Dispose(); 
        }


    If my post is helpful,please help to vote as helpful, if my post solve your question, please help to make it as answer. my sample

    2013年6月12日 11:17