-1

I have a multi-page tiff created on TiffBitmapEncoder te= new TiffBitmapEncoder(); (using CCITT4)

Then I copy this to a memory stream Say MemoryStream ms = new MemoryStream() using ts.save(ms);

Now this memory stream has a tiff image of many pages. I just need to write it to to tiff file. I don't want to write it again through Bitmap.Save(location,coded,parameters) as using (long)EncoderValue.CompressionCCITT4 produces error on 2003 windows machines.

I tried resetting ms to position 0 and writing to a Image and save to an imagelocation. But this writes only 1 page tiff.

How can I do this?

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Dexters
  • 2,419
  • 6
  • 37
  • 57
  • 4
    Why not just write directly to a `FileStream`? – John Saunders Mar 05 '13 at 17:11
  • @JohnSaunders You should post that as an answer – Adriano Carneiro Mar 05 '13 at 17:14
  • I suspect this statement "memory stream has a tiff image of many pages" is already false as it is unlikely any code that copies MemoryStream to a file to change data in the stream. (Also showing your call to `CopyTo` to copy memory stream to file would confirm that). – Alexei Levenkov Mar 05 '13 at 17:14
  • @OndrejTucny yeah,I was playing with Image and Bitmap to files so far as I was using the same way to write Images so far. I have been dealing with lots of other issues wrt to this and lost in the last step – Dexters Mar 05 '13 at 17:16
  • @John Just now tried it to filestream before coming here. And found answer here too. Thanks a lot. – Dexters Mar 05 '13 at 17:17
  • @AlexeiLevenkov The problem is with windows 2003 server where CompressionCCITT4 produces error. So had to come up with a work around to create 1bpp image. I cannot use saveadd() of bitmap. – Dexters Mar 05 '13 at 17:18
  • One more time - how did you verified your statement "memory stream has a tiff image of many pages"? I'm almost certain that it does not contain "image of many pages". Please, show your code at least for copying stream to file (The one behind "resetting ms to position 0 and writing to a Image and save to an imagelocation") – Alexei Levenkov Mar 05 '13 at 17:26
  • @AlexeiLevenkov Yes,I was using a modified version of http://social.msdn.microsoft.com/Forums/en-HK/netfxbcl/thread/1585c562-f7a9-4cfd-9674-6855ffaa8653 – Dexters Mar 06 '13 at 22:58
  • As a work around for "Parameter is not valid" for CompressionCCITT4 on Windows Server 2003 and 2008" issue – Dexters Mar 06 '13 at 22:58
  • Used Image.FromStream(memorystream). And I never really worked with any of these methods if these were not supposed to be used that way. I was just trying it out ! – Dexters Mar 06 '13 at 23:09

1 Answers1

3

Simply write directly to a FileStream. There is no need to use a MemoryStream first.

John Saunders
  • 160,644
  • 26
  • 247
  • 397