zoukankan      html  css  js  c++  java
  • 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);
    }

    }
    }
    }
    }

  • 相关阅读:
    Oracle 添加主键和索引
    Oracle中查询主键、外键、sequence、表基本信息等
    Spring工作原理
    Ehcache 缓存使用
    socket编程-java
    oracle触发器详解
    单例模式的几种写法
    [LeetCode] 412. Fizz Buzz 嘶嘶嗡嗡
    LeetCode Top Interview Questions
    [LeetCode] 131. Palindrome Partitioning 回文分割
  • 原文地址:https://www.cnblogs.com/smart--boy/p/5993186.html
Copyright © 2011-2022 走看看