Bitmap简单操作笔记

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace bitmapdemo
{
    class Program
    {
        static void Main(string[] args)
        {
            //设定新图的高度长度参数
            var width = 700;
            var height = 500;

            //剪切大小
            int cutwidth=600;
            int cutheight=400;
            Graphics g;
            Bitmap bm = new Bitmap(@"D:\ip.jpg");
            Bitmap bm3 = new Bitmap(@"D:\1.jpg");
            Bitmap bm2 = new Bitmap(bm3, width, height);  //将原图缩小
            Rectangle rg = new Rectangle(0, 0, cutwidth, cutheight);
            g = Graphics.FromImage(bm2);// bm2上画bm
            g.DrawImage(bm, rg);// 剪裁bm

            bm2.Save("d:/1c.gif", ImageFormat.Gif);//更改原图的格式类型再保存
            //bm2.Save("d:/1c1.jpg", ImageFormat.Jpeg);//更改的原图的大小再保存
        }
    }
}

 

posted @ 2016-11-16 08:20  公众号python学习开发  阅读(336)  评论(0编辑  收藏  举报