开发者

Silverlight 4.0: How to determine the file size of an object in MemoryStream

开发者 https://www.devze.com 2022-12-23 02:29 出处:网络
byte[] imageBytes = Convert.FromBase64String(base64String); MemoryStream ms = new MemoryStream(imageBytes, 0,
byte[] imageBytes = Convert.FromBase64String(base64String);
MemoryStream ms = new MemoryStream(imageBytes, 0,
imageBytes.开发者_如何转开发Length);

How will I determine its file size of an image?


You should be able to determine the size of the stream pretty easy.

MemoryStream ms = new MemoryStream();
int length = ms.Length;

length is now the length of the stream in bytes. This bytenumber should also be the size of any file you would store that contained only this stream.

Edit:

If you mean in pixels you could use something like:

Image img = Image.FromStream(ms);
int width = img.Width;
int height = img.Height;
0

精彩评论

暂无评论...
验证码 换一张
取 消