• winform程序中打开和保存一幅图像


          作为一个c#的初学者,开始感觉自己对于这方面的知识很茫然,懂得非常少,但是我没有放弃,所以我相信坚持下去会好的,对于每一位初学者,大家都不要放弃,大家彼此互勉,下面和大家分享下我写的一个简单的小程序:

          打开和保存一幅图像。本人用的vs2010中的winform利用button控件、pictureBox控件;

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.IO;
    using System.Drawing.Imaging;

    namespace 对话框的使用
    {
    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
    OpenFileDialog ofd = new OpenFileDialog();
    ofd.Multiselect = true;
    ofd.Title = "打开一幅图像";
    ofd.Filter = "媒体文件(*.mp4)|*.mp4|图片文件(*.jpg)|*.jpg|文本文件(*.txt)|*.txt|所有文件(*.*)|*.*";
    ofd.ShowDialog();
    string path = ofd.FileName;
    pictureBox1.Image = Image.FromFile(path);
    pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
    }

    private void button2_Click(object sender, EventArgs e)
    {
    SaveFileDialog sfd = new SaveFileDialog();
    sfd.Title = "保存图片";
    sfd.Filter = "图片文件(*bmp)|*.bmp";
    sfd.FilterIndex = 0;
    sfd.ShowDialog();
    string path = sfd.FileName;
    using (FileStream fsWrite = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write))
    {
    if (pictureBox1.Image != null)
    {
    pictureBox1.Image.Save(fsWrite, System.Drawing.Imaging.ImageFormat.Bmp);
    }

    }
    }
    }
    }

  • 相关阅读:
    【转】Uiautomator Api浅析
    【转】UiAutomator简要介绍
    后台自动启动appium
    adb通过wifi连接Android设备
    Python字符串处理和输入输出
    OJ题目输出的生成
    Weka的使用和二次开发(朴素贝叶斯及其属性选择)
    PointNet++论文理解和代码分析
    VGG-16复现
    二维偏序-最长上升子序列的两种求解方式
  • 原文地址:https://www.cnblogs.com/smart--boy/p/5993186.html
Copyright © 2020-2023  润新知