0

I have a file that has a string of binary. But the binary starts from the character 31, ie the image starts to be written from the character 31. I need this binary from 31 character and then save as an image.

Anyone have an idea that might help me?

Thanks to all

mcamara
  • 731
  • 4
  • 15
  • 26

2 Answers2

0

I would suggest you somehow should wind up something along the lines of MemoryStream + Image.FromStream

http://msdn.microsoft.com/en-us/library/system.io.memorystream(v=vs.80).aspx http://msdn.microsoft.com/en-us/library/system.drawing.image.fromstream.aspx

I cant say anything else as "string of binary" doesnt say much about what kind of data you have on the string :/

One final tip, use MemoryStream.Seek to get past those 31 bytes before calling Image.FromStream

Machinarius
  • 3,637
  • 3
  • 30
  • 53
0

Try this

MemoryStream ms = new MemoryStream(buffer, 31, buffer.Length - 31);
Image img = Image.FromStream(ms);

(UPDATE)

I assumed you have a byte array and not a stream. If you have a stream then just set the position to 31.

fileStream.Position = 31;
Image img = Image.FromStream(fileStream);
Aliostad
  • 80,612
  • 21
  • 160
  • 208
  • So Aliostad i need a Stream to pass in FromStream Parameter. I'm not pass MemoryStream param to Image.FromStream...comprises? – mcamara Jan 05 '11 at 16:29
  • @tom No I don't understand you. `MemoryStream` is derived from `Stream`, so it can be passed to `Image.FromStream`. – CodesInChaos Jan 05 '11 at 16:45
  • I assumed you have a byte array and not a stream. If you have a stream then just set the position to 31. See my updates. – Aliostad Jan 05 '11 at 17:03
  • Yes....I can see it now...MemoryStream is derived from Stream...happens that my binary file was corrupted and Image.FromStream was return error. But now I get it to work – mcamara Jan 05 '11 at 17:11
  • Note that you need to keep the stream open for the lifetime of the image. – CodesInChaos Jan 05 '11 at 17:15