图像显示与保存

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/tingary/article/details/51627974

设计WinForm程序,将图片fy.jpg以指定大小显示在窗体上的PictureBox1控件上,并将显示的图像保存在另一文件中。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        Graphics g;
        Bitmap b;

        private void button1_Click_1(object sender, EventArgs e)
        {
            g = pictureBox1.CreateGraphics();
            b = new Bitmap(Application.StartupPath + @"\fy.jpg");
            g.DrawImage(b, 0, 0);
            b.Dispose();
            g.Dispose();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            b = new Bitmap(Application.StartupPath + @"\fy.jpg");
            Bitmap i = new Bitmap(pictureBox1.Width,pictureBox1.Height);
            g = Graphics.FromImage(i);
            g.DrawImage(b,0,0);
            i.Save(@"D:\fy.jpg",System.Drawing.Imaging.ImageFormat.Gif);
            b.Dispose();
            i.Dispose();
            g.Dispose();
        }
    }
}


 

猜你喜欢

转载自blog.csdn.net/tingary/article/details/51627974