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

C#
0

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;
                }
            }
        }
    }
Posted by: Guest on September-23-2020
0

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

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; 
        } 
}
Posted by: Guest on September-23-2020

Code answers related to "c# web page show 2nd page of tiff on an image control"

C# Answers by Framework

Browse Popular Code Answers by Language