//----引入必要的命名空间 using system.io; using system.drawing.imaging; //----代码部分----//
private byte[] photo;//公用缓冲区 public string sourfilepath;//源图片文件路径 public string objfilepath;//目标图片路径 public int filetostream()//文件到流的转换 { image img = new bitmap(sourfilepath); memorystream stream = new memorystream(); img.save(stream, imageformat.bmp); binaryreader br = new binaryreader(stream); photo = stream.toarray(); stream.close(); return 0; } public image showpic()//根据流显图 { byte[] bytes = photo; memorystream ms = new memorystream(bytes); ms.position = 0; image img = image.fromstream(ms); ms.close(); return img; } public int streamtofile()//反向转换 { byte[] bytes = photo; filestream fs = new filestream(objfilepath, filemode.create, fileaccess.write); fs.write(bytes, 0, bytes.length); fs.flush(); fs.close(); return 0; }
如对本文有疑问, 点击进行留言回复!!
使用Visual Studio2019创建C#项目(窗体应用程序、控制台应用程序、Web应用程序)
C#实现获取本地内网(局域网)和外网(公网)IP地址的方法分析
浅谈Visual Studio 2019 Vue项目的目录结构
网友评论