C# Stream 转 Bitmap 问题

曾国求 发布于 2012/03/03 22:07
阅读 3K+
收藏 0
C#
我碰到一个很奇怪的问题,同一个Stream,我在windowmobile下,通过new Bitmap(Stream)的方式能成功转成图片,在winform下用同样的方法却老是报参数无效的错误。各位高手帮忙分析下是什么问题,谢谢
加载中
0
IdleMan
IdleMan
逐行debug,看看代码有问题没
0
曾国求
曾国求
public Bitmap test()
  {
  string values = "0,0,44,22,255,255,255,255,255,240,255,255,255,255,255,240,255,255,255,255,255,240,255,255,255,255,255,240,255,255,255,255,255,240,248,15,3,240,63,240,251,255,125,247,223,240,251,255,125,247,223,240,251,255,125,247,223,240,248,15,125,247,223,240,251,255,3,240,63,240,251,255,119,247,127,240,251,255,123,247,191,240,251,255,123,247,191,240,248,15,125,247,223,240,255,255,255,255,255,240,255,255,255,255,255,240,255,255,255,255,255,240,255,255,255,255,255,240,255,255,255,255,255,240,255,255,255,255,255,240,255,255,255,255,255,240";
  string[] vs = values.Split(',');
  List<byte> byteList = new List<byte>();
  foreach (string value in vs)
  {
  int i = Convert.ToInt16(value);
  byteList.Add((byte)i);
  }
  Stream memoryStream = new MemoryStream(byteList.ToArray());
  Bitmap bmap = new Bitmap(memoryStream);
  memoryStream.Close();
  return bmap;
  }
这是代码,在windowmobile下是没问题的,在winform下Bitmap bmap = new Bitmap(memoryStream)这行代码报异常了,“参数不正确”
0
剑神
剑神
这种情况其实是很常见的,极有可能是这个函数的函数原型在windowmobile和windowform下各自参数不一样,因为这两个平台明显不一样,所以相应的函数库自然也不尽相同,要不然就不会有名字上的区别了,建议再好好查查编程手册,看看这个函数的参数具体是什么意思,函数又应该如何调用。
返回顶部
顶部