C#中Bitmap類實現對映像操作的一些方法(Asp.net(C#)-放大縮小圖片尺寸)

來源:互聯網
上載者:User

匯入以下兩個包:
    System.Drawing;
      System.Drawing.Imaging;
建產對象:
     Bitmap bm = new Bitmap("c:/1.bmp");
縮放:
     Bitmap bm1 = new Bitmap(bm,width,height);
格式轉換:
     bm.save("c:/1.jpg",ImageFromat.Jpeg);
     bm1.Save("c:/1.gif", ImageFormat.Gif);
剪下一個地區:
     //剪下大小
    int cutwidth;
      int cutheight;
     Graphics g;
     //以大小為剪下大小,像素格式為32位RGB建立一個位元影像對像
     Bitmap bm1 = new Bitmap(width,height,PixelFormat.Format32bppRgb) ;
    //定義一個地區
     Rectangle rg = new Rectangle(0,0,cutwidth,cutheight);
     //要繪製到的位元影像
     g = Graphics.FromImage(bm1);
     //將bm內rg所指定的地區繪製到bm1
     g.DrawImage(bm,rg)

 

Asp.net(C#)-放大縮小圖片尺寸

 /// <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();
    }

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.