欢迎访问!
您的支持是我们不断前行的动力!

C# 按比例变化图片尺寸

参数times为小数则图片为放大,如times=0.5,则图片放大两倍

/// <summary>
/// 按比例变化图片尺寸
/// </summary>
/// <param name="bm">原图</param>
/// <param name="times">变化倍数</param>
/// <returns></returns>
public static Bitmap ZoomPicture(Bitmap bm, double times)
{
    int nowWidth = (int)(bm.Width / times);
    int nowHeight = (int)(bm.Height / times);
    Bitmap newbm = new Bitmap(nowWidth, nowHeight);
    if (times >= 1 && times <= 1.1)
    {
        newbm = bm;
    }
    else
    {
        Graphics g = Graphics.FromImage(newbm);
        g.InterpolationMode = InterpolationMode.HighQualityBicubic;
        g.SmoothingMode = SmoothingMode.HighQuality;
        g.CompositingQuality = CompositingQuality.HighQuality;
        g.DrawImage(bm, new Rectangle(0, 0, nowWidth, nowHeight), new Rectangle(0, 0, bm.Width, bm.Height), GraphicsUnit.Pixel);
        g.Dispose();
    }
    return newbm;
}

 

 

赞(1) 打赏
转载请注明出处,未注明出处不得转载,蜘蛛侠 » C# 按比例变化图片尺寸
分享到: 更多 (0)

评论 抢沙发

评论前必须登录!

 

蜘蛛侠,您身边的爬虫专家!

觉得文章有用就打赏一下文章作者吧

支付宝扫一扫打赏

微信扫一扫打赏