c#中memorystream需要用什么指令集
答案:2 悬赏:0 手机版
解决时间 2021-02-09 15:33
- 提问者网友:雾里闻花香
- 2021-02-08 16:09
c#中memorystream需要用什么指令集
最佳答案
- 五星知识达人网友:七十二街
- 2021-02-08 16:14
using System.IO;
全部回答
- 1楼网友:天凉才是好个秋
- 2021-02-08 16:54
MemoryStream的命名空间是System.IO,在 mscorlib.dll 中
创建其支持存储区为内存的流
案例代码:内存流的读取写入操作
private void button4_Click(object sender, EventArgs e)
{
//处理图像
string fileNmae = string.Empty;
OpenFileDialog openFileDialog1 = new OpenFileDialog();
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
fileNmae = openFileDialog1.FileName;
}
else
{
fileNmae = @"d:\对联1.jpg";
}
Bitmap bmp = new Bitmap(fileNmae);
BinaryFormatter bin = new BinaryFormatter();
MemoryStream mem = new MemoryStream();
try
{
bin.Serialize(mem, bmp);
String strString = Convert.ToBase64String(mem.GetBuffer(), 0, Convert.ToInt32(mem.Length));
this.textBox1.Text = strString;
Application.DoEvents();
}
catch (Exception ex)
{
throw (ex);
}
finally
{
mem.Close();
}
}
------------------------------------------
private void button5_Click(object sender, EventArgs e)
{
byte[] bits = Convert.FromBase64String(this.textBox1.Text);
MemoryStream mem = new MemoryStream(bits);
BinaryFormatter bin = new BinaryFormatter();
try
{
object obj = ((object)(bin.Deserialize(mem)));
this.pictureBox1.Image = (Bitmap)obj;
}
catch (Exception ex)
{
throw (ex);
}
finally
{
mem.Close();
}
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯