.NET 產生產生縮圖

來源:互聯網
上載者:User

標籤:ima   產生   for   win   rom   jpeg   arm   span   unit   

 /// <summary>        /// 產生縮圖        /// </summary>        /// <param name="FromImagePath">源圖路徑(絕對路徑)</param>        /// <param name="ToImagePath">縮圖路徑(絕對路徑)</param>        /// <param name="MaxWidth">最大寬度</param>        /// <param name="MaxHeight">最大高度</param>        public static void CreatePic(string FromImagePath, string ToImagePath, double MaxWidth, double MaxHeight)        {            Bitmap tmp = null;            Graphics g = null;            //double Max_width = 110, Max_height = 110;//假設最大寬度以及最大高度            int Width = 0;//框條和卡紙的寬度            int Height = 0;//框條和卡紙的高度            double wmp = 1, hmp = 1, default_pparm = 1;//預設寬的比例,預設高對應的比例,最大寬度比例,最大高度比例,預設實際比例,最大實際比例            System.Drawing.Image imgPic = null;//畫芯            imgPic = System.Drawing.Image.FromFile(FromImagePath);            Width = imgPic.Width;            Height = imgPic.Height;            wmp = MaxWidth / Width;//最大寬度比例            hmp = MaxHeight / Height;//最大高度比例            default_pparm = wmp < hmp ? wmp : hmp;//預設實際比例            if (default_pparm > 1)            {                default_pparm = 1;            }            Width = (int)(Width * default_pparm);            Height = (int)(Height * default_pparm);            tmp = new Bitmap((int)(Width), (int)(Height));//最大的容器            g = Graphics.FromImage(tmp);            //g.FillRectangle(new SolidBrush(Color.White), new Rectangle(0, 0, tmp.Width, tmp.Height));            Rectangle Boxs = new Rectangle(0, 0, imgPic.Width, imgPic.Height);            Rectangle Boxd = new Rectangle(0, 0,                                           (int)(Width), (int)(Height));//算圖的起點            g.DrawImage(imgPic, Boxd, Boxs, GraphicsUnit.Pixel);            tmp.Save(ToImagePath, ImageFormat.Jpeg);        }

 

.NET 產生產生縮圖

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.