博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
WinForm 读取照片文件
阅读量:4029 次
发布时间:2019-05-24

本文共 1394 字,大约阅读时间需要 4 分钟。

1 创建窗体项目,添加一个pictureBox1控件和一个openFileDialog1控件

在这里插入图片描述

//添加引用using System.IO;using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;using System.IO;namespace View{
public partial class OtherForm : Form {
public OtherForm() {
InitializeComponent(); } //定义一组图片变量 byte[] picturebytes; private void upfile_Click(object sender, EventArgs e) {
//定义打开文件的类型,图片格式 openFileDialog1.Filter = "**jpg|*.JPG|*.GIF|*.GIF|*.BMP|*.BMP"; //获取打开图片返回值 if (openFileDialog1.ShowDialog() == DialogResult.OK) {
string fullpath = openFileDialog1.FileName;//文件路径 FileStream fs = new FileStream(fullpath, FileMode.Open); picturebytes = new byte[fs.Length]; BinaryReader br = new BinaryReader(fs); picturebytes = br.ReadBytes(Convert.ToInt32(fs.Length)); MemoryStream ms = new MemoryStream(picturebytes); Bitmap img = new Bitmap(ms); pictureBox1.Image = img; } else {
MessageBox.Show("图片打开失败"); } } }}

2 测试

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

转载地址:http://vnabi.baihongyu.com/

你可能感兴趣的文章
laravel中创建帮助函数文件
查看>>
PHP那点小事--三元运算符
查看>>
解决国内NPM安装依赖速度慢问题
查看>>
Brackets安装及常用插件安装
查看>>
在CentOS 7系统上搭建LNMP 环境
查看>>
Centos 7(Linux)环境下安装PHP(编译添加)相应动态扩展模块so(以openssl.so为例)
查看>>
fastcgi_param 详解
查看>>
Nginx配置文件(nginx.conf)配置详解
查看>>
nginx的location配置详解
查看>>
Nginx配置多个项目使用同一端口号的办法
查看>>
Linux下用户组、文件权限详解
查看>>
GitHub与Git指令入门
查看>>
Laravel如何引用第三方(自定义)库
查看>>
Windows 7 下安装sqlite数据库
查看>>
sqlite中一些常用的命令及解释
查看>>
数据库SQL优化大总结之 百万级数据库优化方案
查看>>
Windows下安装MySQL解压缩版
查看>>
企业级监控管理平台建设密谈
查看>>
新基建
查看>>
Google SRE Four Golden Signals
查看>>