Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
745 views
in Technique[技术] by (71.8m points)

asp.net - C#: How do I convert a multi-page TIFF via MemoryStream into one long image?

So I have been able to take a multi-page TIFF file and convert it to a single jpeg image but it flattens the TIFF. By flatten it, I mean it only returns the first page. The goal is to retrieve the TIFF (via memory stream), open each page of the TIFF and append it to a new jpeg (or any web image). Thus creating one long image to view on the web without the aid of a plugin. I do have the MODI.dll installed but I am not sure how to use it in this instance but it is an option.

  • Source Code (using a FileHandler):

    #region multi-page tiff to single page jpeg
    var byteFiles = dfSelectedDocument.File.FileBytes; // <-- FileBytes is a byte[] or byte array source.
    
    byte[] jpegBytes;
    using( var inStream = new MemoryStream( byteFiles ) )
    using( var outStream = new MemoryStream() ) {
    System.Drawing.Image.FromStream( inStream ).Save( outStream, ImageFormat.Jpeg );
    jpegBytes = outStream.ToArray();
    }
    
     context.Response.ContentType = "image/JPEG";
     context.Response.AddHeader( "content-disposition", 
        string.Format( "attachment;filename="{0}"",
        dfSelectedDocument.File.FileName.Replace( ".tiff", ".jpg" ) ) 
     );
     context.Response.Buffer = true;
     context.Response.BinaryWrite( jpegBytes );
    #endregion
    
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...