c# web page show 2nd page of tiff on an image control

  public static class ConvertTiffToJpeg
    {
        static string base64String = null;
        public static string ImageToBase64(string tifpath)
        {
            string path = tifpath;
            using (System.Drawing.Image image = System.Drawing.Image.FromFile(path))
            {
                using (MemoryStream m = new MemoryStream())
                {
                    image.Save(m, ImageFormat.Jpeg);
                    byte[] imageBytes = m.ToArray();
                    base64String = Convert.ToBase64String(imageBytes);
                    return base64String;
                }
            }
        }
    }

3.86
7

                                    public static string[] ConvertTiffToJpeg(string fileName) 
{ 
        using (Image imageFile = Image.FromFile(fileName)) 
        { 
            FrameDimension frameDimensions = new FrameDimension( 
                imageFile.FrameDimensionsList[0]); 

            // Gets the number of pages from the tiff image (if multipage) 
            int frameNum = imageFile.GetFrameCount(frameDimensions); 
            string[] jpegPaths = new string[frameNum]; 

            for (int frame = 0; frame < frameNum; frame++) 
            { 
                // Selects one frame at a time and save as jpeg. 
                imageFile.SelectActiveFrame(frameDimensions, frame); 
                using (Bitmap bmp = new Bitmap(imageFile)) 
                { 
                    jpegPaths[frame] = String.Format("{0}\\{1}{2}.jpg",  
                        Path.GetDirectoryName(fileName), 
                        Path.GetFileNameWithoutExtension(fileName),  
                        frame); 
                    bmp.Save(jpegPaths[frame], ImageFormat.Jpeg); 
                } 
            } 

            return jpegPaths; 
        } 
} 

3.86 (7 Votes)
0
Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source