1
using (MemoryStream mem = new MemoryStream(data))
{
    System.Drawing.Image imgPhoto = System.Drawing.Image.FromStream(mem);
}

This is the code that I am using . The problem is that as soon as that debugger processes this line :

System.Drawing.Image imgPhoto = System.Drawing.Image.FromStream(mem);

It gives an error parameter invalid . So after I checked the parameters for "mem" while it is debugging , I noticed that the position parameter is setting to zero every time .

I noticed one more thing here : when I am receiving images from sources beginning with url :

enter image description here

The position parameter is not setting to some value and always setting to zero and that's the time when I am getting the error . Please refer the screen shot .

But for images beginning with URL : ... The position parameter is setting some value . Please refer the screenshot .

Guy
  • 46,488
  • 10
  • 44
  • 88
bijitm
  • 59
  • 4
  • 3
    This might be unrelated but you must not dispose the memory stream as long as the image is used. The `Image` class takes ownership of the stream. – Dirk Apr 13 '17 at 12:10
  • The [documentaiton](https://msdn.microsoft.com/en-us/library/93z9ee4x(v=vs.110).aspx) says _The stream is reset to zero if this method is called successively with the same stream._ Also If you're saying the stream contains more than just the image data then you need to process the stream so you only pass the image data in via a new stream. – juharr Apr 13 '17 at 12:12
  • I am really very sorry guys as the second image is not given here so i posted the same thing again giving both the images so can you please refer the other post ... I dont know how you can manage to understand this thing as this post is incomplete :D ... so please refer this post ... https://stackoverflow.com/questions/43405071/image-fromstream-memorystream-object – bijitm Apr 14 '17 at 04:17
  • If you understood the mistake that i did then please post some code snippet giving the right code ... that would be very nice – bijitm Apr 14 '17 at 04:20
  • I did the limit count to 1 so that it can process only a single image ... it's still not working ... I guess the problem is with the images coming from external Sources as you see in the screenshots because it easily processes the images coming from scontent source... In case of scontent images the position parameter is setting to some value but the same thing is not happening in case of external images ... Please provide a solution for this thing as this thing is just getting over me... : / – bijitm Apr 14 '17 at 05:03

0 Answers0