MemoryStream错误? [英] MemoryStream bug?
问题描述
当我运行以下代码时,MemoryStream的位置始终设置为
762而不是0,这是我所期望的:
Dim bmp如图像
Dim ms作为MemoryStream
ms = New MemoryStream
bmp.Save(ms,bmp.RawFormat)
Console.WriteLine(" MemoryStream Position ="& ms.Position )
ms.Close()
这种情况发生在两台不同的电脑上。这是否发生在其他人身上?
?有没有理由将内存流的位置设置为
762而不是0?或者在第一次创建它时总是手动将流
位置设置为零是正确的做法吗?
- Don
When I run the following code, the MemoryStream''s Position is always set to
762 instead of 0, which is what I would expect:
Dim bmp As Image
Dim ms As MemoryStream
bmp = New System.Drawing.Bitmap("C:\2068.bmp")
ms = New MemoryStream
bmp.Save(ms, bmp.RawFormat)
Console.WriteLine("MemoryStream Position = " & ms.Position)
ms.Close()
This is happening on two different computers for me. Does this happen to
anyone else? Is there a reason why the memory stream''s position is set to
762 instead of 0? Or is it proper practice to always manually set stream
positions to zero when first creating them?
- Don
推荐答案
Don,
|这是否发生在
|还有谁?
是
|有没有理由将内存流的位置设置为
| 762而不是0?
是的,因为我怀疑bmp.Save语句写了762字节的信息
到流。
| bmp.Save(ms,bmp.RawFormat)
| Console.WriteLine(" MemoryStream Position =" ms.Position)
看到Image.Save正在向流中写入信息,我希望
流实际移动的位置,所以当我向源流写入更多信息时,流被定位到可写状态。位置......
|或者总是手动设置流
|是正确的做法首次创建它们时位置为零?
不,我在第一次创建它时没有设置位置。
希望这有帮助
Jay
" Don" <未***** @ oblivion.com>在消息中写道
news:kwCye.1872153
Don,
| Does this happen to
| anyone else?
Yes
| Is there a reason why the memory stream''s position is set to
| 762 instead of 0?
Yes, as I suspect that the bmp.Save statement wrote 762 bytes of information
to the stream.
| bmp.Save(ms, bmp.RawFormat)
| Console.WriteLine("MemoryStream Position = " & ms.Position)
Seeing as Image.Save is writing information to the stream, I would expect
the stream''s position to actually move, so when I write more information to
the stream the stream is positioned to a "writable" position...
| Or is it proper practice to always manually set stream
| positions to zero when first creating them?
No, I don''t set the position when first creating them.
Hope this helps
Jay
"Don" <un*****@oblivion.com> wrote in message
news:kwCye.1872153
6l.739353@pd7tw2no ...
|当我运行以下代码时,MemoryStream的位置始终设置为
to
| 762而不是0,这是我所期望的:
|
|
| Dim bmp As Image
| Dim ms As MemoryStream
|
| bmp = New System.Drawing.Bitmap(" C:\\ _2068.bmp")
| ms =新的MemoryStream
| bmp.Save(ms,bmp.RawFormat)
| Console.WriteLine(&MemoryStream Position ="& ms.Position)
| ms.Close()
|
|
|这种情况发生在两台不同的计算机上。这是否发生在
|还有谁?有没有理由将内存流的位置设置为
| 762而不是0?或者总是手动设置流
|是正确的做法首次创建时位置为零?
|
| - Don
|
|
6l.739353@pd7tw2no...
| When I run the following code, the MemoryStream''s Position is always set
to
| 762 instead of 0, which is what I would expect:
|
|
| Dim bmp As Image
| Dim ms As MemoryStream
|
| bmp = New System.Drawing.Bitmap("C:\2068.bmp")
| ms = New MemoryStream
| bmp.Save(ms, bmp.RawFormat)
| Console.WriteLine("MemoryStream Position = " & ms.Position)
| ms.Close()
|
|
| This is happening on two different computers for me. Does this happen to
| anyone else? Is there a reason why the memory stream''s position is set to
| 762 instead of 0? Or is it proper practice to always manually set stream
| positions to zero when first creating them?
|
| - Don
|
|
" Don" <未***** @ oblivion.com> schrieb:
"Don" <un*****@oblivion.com> schrieb:
bmp = New System.Drawing.Bitmap(" C:\\\ n2068.bmp")
ms = New MemoryStream
bmp.Save(ms,bmp。 RawFormat)
Console.WriteLine(" MemoryStream Position =& ms.Position)
ms.Close()
这对我来说是在两台不同的计算机上发生的。这是否发生在其他人身上?有没有理由将内存流的位置设置为762而不是0?
bmp = New System.Drawing.Bitmap("C:\2068.bmp")
ms = New MemoryStream
bmp.Save(ms, bmp.RawFormat)
Console.WriteLine("MemoryStream Position = " & ms.Position)
ms.Close()
This is happening on two different computers for me. Does this happen to
anyone else? Is there a reason why the memory stream''s position is set to
762 instead of 0?
我认为它是由编写的数据到流。通过写入数据,
输入位置将增加写入
流的字节数。
- < br $>
MS Herfried K. Wagner
MVP< URL:http://dotnet.mvps.org/>
VB< URL: http://classicvb.org/petition/>
I assume it''s caused by writing the data to the stream. By writing data the
input position will be incremented by the number of bytes written to the
stream.
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
这篇关于MemoryStream错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!