image.save的问题

jmghoul 2009-08-13 10:49:05
我想把一副绘制好的画面存放到GraphicsStream中 以下代码写在一个按钮事件中 点击按钮绘制并储存图片到GraphicsStream
Bitmap bp = new Bitmap(panel1.ClientRectangle.Width, panel1.ClientRectangle.Height);
bp.MakeTransparent(Color.FromArgb(0, Color.White));
Graphics g = Graphics.FromImage(bp);
Graphics g1 = panel1.CreateGraphics();
g1.Clear(Color.White);
g.DrawString("测试字符串", new Font("宋体", 10), new SolidBrush(Color.Black), new Point(100, 100));
g1.DrawImage(bp, new Point(0, 0));
//以上就是绘制图片到 panel1中
GraphicsStream gs = new GraphicsStream(new IntPtr(IntPtr.Size), IntPtr.Size, true, true);

bp.Dispose();
bp.Save(gs, ImageFormat.Bmp); //此处异常:参数无效 如果我改用MemoryStream定义gs一样会出这个异常


g.Dispose();
g1.Dispose();
...全文
650 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
dancingbit 2009-08-13
  • 打赏
  • 举报
回复
我没有有过Bitmap绘图,我只是猜测可能这样创建的Bitmap会有问题。
jmghoul 2009-08-13
  • 打赏
  • 举报
回复
bitmap本身的问题是什么意思啊 你可以简单给我些个用bitmap绘图然后存到menorystream再把menorystream用image.fromstream()画出来的代码么
dancingbit 2009-08-13
  • 打赏
  • 举报
回复
改第二个参数之后还有问题的话,就是你的Bitmap本身的问题。
jmghoul 2009-08-13
  • 打赏
  • 举报
回复
我用menorystream也有问题
dancingbit 2009-08-13
  • 打赏
  • 举报
回复
bp.Save(gs, ImageFormat.Bmp);
----------------------------
我用MemoryStream没有问题的,不过你可以这样改一下看看:
bp.Save(gs, bp.RawFormat);

或者也可能就是这个Bitmap本身有问题。
jmghoul 2009-08-13
  • 打赏
  • 举报
回复
我都看了 Map Save(Stream, ImageFormat) 参数类型没错 就是说参数无效 很郁闷
我是在winform窗体中 一个按钮事件里写的
卧_槽 2009-08-13
  • 打赏
  • 举报
回复
看帮助
LutzMark 2009-08-13
  • 打赏
  • 举报
回复
貌似移动平台的Bitmap类实现和桌面程序的不太一样
看看你使用的Bitmap类中Save方法的参数说明
jmghoul 2009-08-13
  • 打赏
  • 举报
回复
Bitmap bp = new Bitmap(panel1.ClientRectangle.Width, panel1.ClientRectangle.Height);
bp.MakeTransparent(Color.FromArgb(0, Color.White));
Graphics g = Graphics.FromImage(bp);
Graphics g1 = panel1.CreateGraphics();
g1.Clear(Color.White);
g.DrawString("测试字符串", new Font("宋体", 10), new SolidBrush(Color.Black), new Point(100, 100));
g1.DrawImage(bp, new Point(0, 0));
//以上就是绘制图片到 panel1中
MemoryStream gs = new MemoryStream(); // 这个地方改成MemoryStream 还是参数无效

bp.Dispose();
bp.Save(gs, ImageFormat.Bmp); //此处异常:参数无效 如果我改用MemoryStream定义gs一样会出这个异常


g.Dispose();
g1.Dispose();

麻烦谁有用MemoryStream成功的代码发一下 我在机器上试试
flyerwing 2009-08-13
  • 打赏
  • 举报
回复
我用MemoryStream没有问题的
dancingbit 2009-08-13
  • 打赏
  • 举报
回复
我用MemoryStream保存过很多次Bitmap,都没有问题。
是不是在Mobile中不支持?
jmghoul 2009-08-13
  • 打赏
  • 举报
回复
没有问题的 可以 画出来 就是存的时候发生异常 参数无效异常 参数都是按照一样类型写的 很费解

110,567

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧