本文介绍了内存流不能消耗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一条代码可以像这样从sqldatabase中读取图像.

hi guys i have a code to read the image from sqldatabase like.

Byte[] imagedata = new Byte[0];



              imagedata = (byte[])dr[45];
              System.Drawing.Image b = null;
              MemoryStream mm = new MemoryStream(imagedata);
              byte[] buffer = new byte[4096];
              int byteseq = mm.Read(imagedata, 0, 4096);
              while (byteseq > 0)
              {
                  //mm.Write(buffer, 0, byteseq);
                 // int byteseq = mm.Read(imagedata, 0,4096);
                  mm.Write(buffer, 0, buffer.Length);// Getting the error memory stream can not be expendable



您能否帮助我解决此错误..



can u please help me to solve this error..

推荐答案

byte[] buffer = File.ReadAllBytes("filaname.docx");
MemoryStream ms = new MemoryStream(buffer);
MemoryStream ms2 = new MemoryStream();
ms2.Write(buffer, 0, buffer.Length);


那么,ms将不可扩展,ms2将不可扩展.因此,如果您要修改流,并且大小可能会增加,则第一个ctor将不起作用,但是第二个方法将可以正常工作.

希望能对您有所帮助:)

来源: http://weblogs.asp.净/ashicmahtab/archive/2008/08/25/memorystream-not-expandable-invalid-operation-exception.aspx [ ^ ]


then, ms will NOT be expandable, ms2 will be. So, if you are modifying the stream and the size may increase, the first ctor will not work, but the second approach will work just fine.

Hope that helps :)

Source: http://weblogs.asp.net/ashicmahtab/archive/2008/08/25/memorystream-not-expandable-invalid-operation-exception.aspx[^]


这篇关于内存流不能消耗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 19:55