C#保存图片的问题
希望高手指教!首先在窗体中创建了一个menuSrip1和pictureBox1//定义数据byte[]imagedata;byte[,]martrix;/*点击菜单中的打...
希望高手指教!
首先在窗体中创建了一个menuSrip1和pictureBox1
//定义数据
byte[] imagedata;
byte[,] martrix;
/*点击菜单中的打开图像按钮,会弹出对话框,选择一幅图片,就可以打开显示在pictureBox1上了,并且,图像中的数据保存进了imagedata数组*/
private void 打开图像ToolStripMenuItem_Click(object sender, EventArgs e)
{
Stream myStream;
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "C:\\Documents and Settings\\Administrator\\My Documents\\My Pictures";
openFileDialog1.Filter = "BMP图形文件 (*.bmp)|*.bmp";
openFileDialog1.FilterIndex = 1;
openFileDialog1.RestoreDirectory = true;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
if ((myStream = openFileDialog1.OpenFile()) != null)
{
pictureBox1.Image = new Bitmap(openFileDialog1.FileName);
Image photo = pictureBox1.Image;
System.IO.MemoryStream ms = new System.IO.MemoryStream();
photo.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
imagedata = ms.GetBuffer();
/*点击操作按钮会对imagedata中的数据进行一些操作,具体算法这里就省略了,反正操作以后经过手动输出数组确定算法正确*/
private void 操作ToolStripMenuItem_Click(object sender, EventArgs e)
{
//这里进行一系列操作
/*按理说,下面就应该把数组重新变回图像,并显示在pictureBox1中。即实现刷新显示,pictureBox1中原来的图像没有了,变成经过操作以后的图像,这一段不知该如何做*/
}
/*最后简单了,点击另存为按钮,会弹出对话框,这时可以把pictureBox1中的图像保存进电脑。这段也测试成功了*/
private void 另存为ToolStripMenuItem_Click(object sender, EventArgs e)
{
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.InitialDirectory = "C:\\Documents and Settings\\Administrator\\My Documents\\My Pictures";
saveFileDialog1.Filter = "Bitmap Image|*.bmp";
saveFileDialog1.Title = "保存图像";
saveFileDialog1.ShowDialog();
if(saveFileDialog1.FileName != "")
{
{
pictureBox1.Image.Save(saveFileDialog1.FileName, System.Drawing.Imaging.ImageFormat.Bmp);
}
}
出现错误提示。怎么办。。。 展开
首先在窗体中创建了一个menuSrip1和pictureBox1
//定义数据
byte[] imagedata;
byte[,] martrix;
/*点击菜单中的打开图像按钮,会弹出对话框,选择一幅图片,就可以打开显示在pictureBox1上了,并且,图像中的数据保存进了imagedata数组*/
private void 打开图像ToolStripMenuItem_Click(object sender, EventArgs e)
{
Stream myStream;
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "C:\\Documents and Settings\\Administrator\\My Documents\\My Pictures";
openFileDialog1.Filter = "BMP图形文件 (*.bmp)|*.bmp";
openFileDialog1.FilterIndex = 1;
openFileDialog1.RestoreDirectory = true;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
if ((myStream = openFileDialog1.OpenFile()) != null)
{
pictureBox1.Image = new Bitmap(openFileDialog1.FileName);
Image photo = pictureBox1.Image;
System.IO.MemoryStream ms = new System.IO.MemoryStream();
photo.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
imagedata = ms.GetBuffer();
/*点击操作按钮会对imagedata中的数据进行一些操作,具体算法这里就省略了,反正操作以后经过手动输出数组确定算法正确*/
private void 操作ToolStripMenuItem_Click(object sender, EventArgs e)
{
//这里进行一系列操作
/*按理说,下面就应该把数组重新变回图像,并显示在pictureBox1中。即实现刷新显示,pictureBox1中原来的图像没有了,变成经过操作以后的图像,这一段不知该如何做*/
}
/*最后简单了,点击另存为按钮,会弹出对话框,这时可以把pictureBox1中的图像保存进电脑。这段也测试成功了*/
private void 另存为ToolStripMenuItem_Click(object sender, EventArgs e)
{
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.InitialDirectory = "C:\\Documents and Settings\\Administrator\\My Documents\\My Pictures";
saveFileDialog1.Filter = "Bitmap Image|*.bmp";
saveFileDialog1.Title = "保存图像";
saveFileDialog1.ShowDialog();
if(saveFileDialog1.FileName != "")
{
{
pictureBox1.Image.Save(saveFileDialog1.FileName, System.Drawing.Imaging.ImageFormat.Bmp);
}
}
出现错误提示。怎么办。。。 展开
3个回答
展开全部
private void 操作ToolStripMenuItem_Click(object sender, EventArgs e)
{
//这里进行一系列操作
//把imagedata运算之后.
System.IO.MemoryStream ls = new System.IO.MemoryStream(imagedata); //把byte[]载入流
Image img = Image.FromStream(ls); //流保存成image
this.pictureBox1.Image = img;
}
补充:
Bitmap bitmap = Image.FromStream(ms);
{
//这里进行一系列操作
//把imagedata运算之后.
System.IO.MemoryStream ls = new System.IO.MemoryStream(imagedata); //把byte[]载入流
Image img = Image.FromStream(ls); //流保存成image
this.pictureBox1.Image = img;
}
补充:
Bitmap bitmap = Image.FromStream(ms);
展开全部
private void 操作ToolStripMenuItem_Click(object sender, EventArgs e)
{
//这里进行一系列操作
System.IO.MemoryStream ms = new System.IO.MemoryStream(imagedata, false);
Bitmap bmp = new Bitmap(ms);
pictureBox1.Image = null;
pictureBox1.Refresh();
pictureBox1.Image = bmp;
}
{
//这里进行一系列操作
System.IO.MemoryStream ms = new System.IO.MemoryStream(imagedata, false);
Bitmap bmp = new Bitmap(ms);
pictureBox1.Image = null;
pictureBox1.Refresh();
pictureBox1.Image = bmp;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
imagedata要先分配空间
或者你想办法返回一个数组付赋给他
我已经给你一个方案了不知道可以吗?
或者你想办法返回一个数组付赋给他
我已经给你一个方案了不知道可以吗?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询