C#中Bitmap类实现对图像操作的一些方法(Asp.net(C#)-放大缩小图片尺寸)

导入以下两个包:
    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();
    } Asp.net(C)-放大缩小图片尺寸 - 潇湘客www.xzbwww.com - 潇湘客(华软英创工作室)

 

你可能感兴趣的:(asp.net)