Memory stream
-
Hi all .. I'm trying to save an image from memory stream content. but getting error like "Parameter is not valid." at newImage = System.Drawing.Image.FromStream(ms); can you please suggest me. Here is my code..
System.Drawing.Image newImage;
using (MemoryStream ms = new MemoryStream(photoByte, 0, photoByte.Length))
{ms.Write(photoByte, 0, photoByte.Length); newImage = System.Drawing.Image.FromStream(ms); newImage.Save(strFileName); img.Attributes.Add("src", strFileName); }
Thanks
siri
-
Hi all .. I'm trying to save an image from memory stream content. but getting error like "Parameter is not valid." at newImage = System.Drawing.Image.FromStream(ms); can you please suggest me. Here is my code..
System.Drawing.Image newImage;
using (MemoryStream ms = new MemoryStream(photoByte, 0, photoByte.Length))
{ms.Write(photoByte, 0, photoByte.Length); newImage = System.Drawing.Image.FromStream(ms); newImage.Save(strFileName); img.Attributes.Add("src", strFileName); }
Thanks
siri
-
After writing to the stream you have to reset the position to the beginning of the stream before reading it.
Despite everything, the person most likely to be fooling you next is yourself.
Thanks for your reply.. but.. still i'm getting same error Thanks
siri
-
Hi all .. I'm trying to save an image from memory stream content. but getting error like "Parameter is not valid." at newImage = System.Drawing.Image.FromStream(ms); can you please suggest me. Here is my code..
System.Drawing.Image newImage;
using (MemoryStream ms = new MemoryStream(photoByte, 0, photoByte.Length))
{ms.Write(photoByte, 0, photoByte.Length); newImage = System.Drawing.Image.FromStream(ms); newImage.Save(strFileName); img.Attributes.Add("src", strFileName); }
Thanks
siri
sirisha guttikonda wrote:
new MemoryStream(photoByte, 0, photoByte.Length)
sirisha guttikonda wrote:
ms.Write(photoByte, 0, photoByte.Length);
When you call
new MemoryStream(photoByte, 0, photoByte.Length)
, the contents in thephotoByte
will be written to the stream. So calling theWrite()
again is pointless. Here is a code which worked at my endusing(MemoryStream stream = new MemoryStream(photoByte,0,photoByte.Length))
using (Image image = Image.FromStream(stream))
{
image.Save(@"filename.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
}All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions
-
sirisha guttikonda wrote:
new MemoryStream(photoByte, 0, photoByte.Length)
sirisha guttikonda wrote:
ms.Write(photoByte, 0, photoByte.Length);
When you call
new MemoryStream(photoByte, 0, photoByte.Length)
, the contents in thephotoByte
will be written to the stream. So calling theWrite()
again is pointless. Here is a code which worked at my endusing(MemoryStream stream = new MemoryStream(photoByte,0,photoByte.Length))
using (Image image = Image.FromStream(stream))
{
image.Save(@"filename.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
}All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions
Thank You...
siri