xscape
xscape

Reputation: 3376

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

byte[] imageBytes = Convert.FromBase64String(base64String);
MemoryStream ms = new MemoryStream(imageBytes, 0,
imageBytes.Length);

How will I determine its file size of an image?

Upvotes: 0

Views: 551

Answers (1)

Alxandr
Alxandr

Reputation: 12431

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;

Upvotes: 4

Related Questions