Search Results for

    Show / Hide Table of Contents

    FlexCel image explorer (C# / netframework)

    Note

    This demo is available in your FlexCel installation at <FlexCel Install Folder>\samples\csharp\VS2022\netframework\10.API\30.FlexCelImageExplorer and also at https:​//​github.​com/​tmssoftware/​TMS-​FlexCel.​NET-​demos/​tree/​master/​csharp/​VS2022/​netframework/​Modules/​10.​API/​30.​FlexCel​Image​Explorer

    Overview

    This is an application that will show all the images in an Excel file, to show their real size and bit depth. It will also allow you to extract those images to files. Note that the first time you open a file it can take some time, as it opens ALL the xls files on the folder and extracts all the image information so it can highlight files with problems.

    Concepts

    • How to use the API to read the images on a file.

    • How to convert the images to 256 colors or black and white using GDI+

    • On the left pane, files in red are files that have a cropped image. (that is, the image stored is larger than the image shown on Excel). Having this cropped image only consumes disk space, and makes rendering to pdf slower, as the image has to be decoded, cropped to the real size and encoded again.

    • Bold entries on the left pane are images with true color and transparency. Those images can get very big quite fast, so it is better if you can convert them to indexed color. Also, file with true color and transparency have to be re-encoded when exporting to pdf, making the process slower.

    Files

    AssemblyInfo.cs

    using System.Reflection;
    using System.Runtime.CompilerServices;
    
    //
    // General Information about an assembly is controlled through the following 
    // set of attributes. Change these attribute values to modify the information
    // associated with an assembly.
    //
    [assembly: AssemblyTitle("")]
    [assembly: AssemblyDescription("")]
    [assembly: AssemblyConfiguration("")]
    [assembly: AssemblyCompany("")]
    [assembly: AssemblyProduct("")]
    [assembly: AssemblyCopyright("(c) 2002 - 2025 TMS Software")]
    [assembly: AssemblyTrademark("")]
    [assembly: AssemblyCulture("")]
    
    //
    // Version information for an assembly consists of the following four values:
    //
    //      Major Version
    //      Minor Version 
    //      Build Number
    //      Revision
    //
    // You can specify all the values or you can default the Revision and Build Numbers 
    // by using the '*' as shown below:
    
    [assembly: AssemblyVersion("7.24.0.0")]
    
    //
    // In order to sign your assembly you must specify a key to use. Refer to the 
    // Microsoft .NET Framework documentation for more information on assembly signing.
    //
    // Use the attributes below to control which key is used for signing. 
    //
    // Notes: 
    //   (*) If no key is specified, the assembly is not signed.
    //   (*) KeyName refers to a key that has been installed in the Crypto Service
    //       Provider (CSP) on your machine. KeyFile refers to a file which contains
    //       a key.
    //   (*) If the KeyFile and the KeyName values are both specified, the 
    //       following processing occurs:
    //       (1) If the KeyName can be found in the CSP, that key is used.
    //       (2) If the KeyName does not exist and the KeyFile does exist, the key 
    //           in the KeyFile is installed into the CSP and used.
    //   (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility.
    //       When specifying the KeyFile, the location of the KeyFile should be
    //       relative to the project output directory which is
    //       %Project Directory%\obj\<configuration>. For example, if your KeyFile is
    //       located in the project directory, you would specify the AssemblyKeyFile 
    //       attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]
    //   (*) Delay Signing is an advanced option - see the Microsoft .NET Framework
    //       documentation for more information on this.
    //
    [assembly: AssemblyDelaySign(false)]
    [assembly: AssemblyKeyFile("")]
    [assembly: AssemblyKeyName("")]
    

    MainForm.cs

    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;
    using System.IO;
    
    using FlexCel.Core;
    using FlexCel.XlsAdapter;
    using System.Diagnostics;
    
    namespace FlexCelImageExplorer
    {
        /// <summary>
        /// Image Explorer.
        /// </summary>
        public partial class mainForm: System.Windows.Forms.Form
        {
    
            public mainForm()
            {
                InitializeComponent();
                GetCurrencyManager.CurrentChanged += new EventHandler(CurrentRowChanged);
                ResizeToolbar(mainToolbar);
            }
    
            private void ResizeToolbar(ToolStrip toolbar)
            {
    
                using (Graphics gr = CreateGraphics())
                {
                    double xFactor = gr.DpiX / 96.0;
                    double yFactor = gr.DpiY / 96.0;
                    toolbar.ImageScalingSize = new Size((int)(24 * xFactor), (int)(24 * yFactor));
                    toolbar.Width = 0; //force a recalc of the buttons.
                }
            }
    
            private string CurrentFilename = null;
            private TCompressForm CompressForm;
    
            private CurrencyManager GetCurrencyManager
            {
                get
                {
                    return (CurrencyManager)this.BindingContext[dataGrid.DataSource, dataGrid.DataMember];
                }
            }
    
            private int GetImagePos
            {
                get
                {
                    return GetCurrencyManager.Position;
                }
            }
    
            private void btnExit_Click(object sender, System.EventArgs e)
            {
                Close();
            }
    
            private void btnOpenFile_Click(object sender, System.EventArgs e)
            {
                if (openFileDialog1.ShowDialog() != DialogResult.OK) return;
                OpenFile(openFileDialog1.FileName);
                if (cbScanFolder.Checked) FillListBox();
            }
    
            private bool GetHasCrop(TImageProperties ImgProps)
            {
                return ImgProps.CropArea.CropFromLeft != 0 ||
                    ImgProps.CropArea.CropFromRight != 0 ||
                    ImgProps.CropArea.CropFromTop != 0 ||
                    ImgProps.CropArea.CropFromBottom != 0;
            }
    
            private void FillListBox()
            {
                lblFolder.Text = "Files on folder: " + Path.GetDirectoryName(openFileDialog1.FileName);
                DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(openFileDialog1.FileName));
                FileInfo[] Fi = di.GetFiles("*.xls");
                FilesListBox.Items.Clear();
    
                TImageInfo[] Files = new TImageInfo[Fi.Length];
    
                for (int k = 0; k < Fi.Length; k++)
                {
                    FileInfo f = Fi[k];
                    bool HasCrop = false;
                    bool HasARGB = false;
                    XlsFile x1 = new XlsFile();
    
                    bool HasImages = false;
    
                    try
                    {
                        x1.Open(f.FullName);
                        for (int sheet = 1; sheet <= x1.SheetCount; sheet++)
                        {
                            x1.ActiveSheet = sheet;
                            for (int i = x1.ImageCount; i > 0; i--)
                            {
                                HasImages = true;
                                TImageProperties ip = x1.GetImageProperties(i);
                                if (!HasCrop) HasCrop = GetHasCrop(ip);
    
                                TXlsImgType imgType = TXlsImgType.Unknown;
                                using (MemoryStream ms = new MemoryStream())
                                {
                                    x1.GetImage(i, ref imgType, ms);
                                    FlexCel.Pdf.TPngInformation PngInfo = FlexCel.Pdf.TPdfPng.GetPngInfo(ms);
                                    if (PngInfo != null)
                                    {
                                        HasARGB = PngInfo.ColorType == 6;
                                    }
                                }
    
                            }
                        }
                    }
                    catch (Exception)
                    {
                        Files[k] = new TImageInfo(f, false, false, false, false);
                        continue;
                    }
    
                    Files[k] = new TImageInfo(f, true, HasCrop, HasImages, HasARGB);
                }
    
                FilesListBox.Items.AddRange(Files);
            }
    
            private void OpenFile(string FileName)
            {
                ImageDataTable.Rows.Clear();
    
                try
                {
                    XlsFile Xls = new XlsFile(true);
                    CurrentFilename = FileName;
                    Xls.Open(FileName);
    
                    for (int sheet = 1; sheet <= Xls.SheetCount; sheet++)
                    {
                        Xls.ActiveSheet = sheet;
                        for (int i = Xls.ImageCount; i > 0; i--)
                        {
                            TXlsImgType ImageType = TXlsImgType.Unknown;
                            byte[] ImgBytes = Xls.GetImage(i, ref ImageType);
                            TImageProperties ImgProps = Xls.GetImageProperties(i);
                            object[] ImgData = new object[ImageDataTable.Columns.Count];
                            ImgData[0] = Xls.SheetName;
                            ImgData[1] = i;
                            ImgData[4] = ImageType.ToString();
                            ImgData[7] = Xls.GetImageName(i);
                            ImgData[8] = ImgBytes;
                            ImgData[9] = GetHasCrop(ImgProps);
    
    
                            using (MemoryStream ms = new MemoryStream(ImgBytes))
                            {
                                FlexCel.Pdf.TPngInformation PngInfo = FlexCel.Pdf.TPdfPng.GetPngInfo(ms);
                                if (PngInfo != null)
                                {
                                    ImgData[2] = PngInfo.Width;
                                    ImgData[3] = PngInfo.Height;
                                    string s = String.Empty;
                                    int bpp = 0;
    
                                    if ((PngInfo.ColorType & 4) != 0)
                                    {
                                        s += "ALPHA-";
                                        bpp = 1;
                                    }
                                    if ((PngInfo.ColorType & 2) == 0)
                                    {
                                        s += "Grayscale -" + (1 << PngInfo.BitDepth).ToString() + " shades. ";
                                        bpp = 1;
                                    }
                                    else
                                    {
                                        if ((PngInfo.ColorType & 1) == 0)
                                        {
                                            bpp += 3;
                                            s += "RGB - " + (PngInfo.BitDepth * (bpp)).ToString() + "bpp.  ";
                                        }
                                        else
                                        {
                                            s += "Indexed - " + (1 << PngInfo.BitDepth).ToString() + " colors. ";
                                            bpp = 1;
                                        }
                                    }
    
                                    ImgData[5] = s;
    
                                    ImgData[6] = (Math.Round(PngInfo.Width * PngInfo.Height * PngInfo.BitDepth * bpp / 8f / 1024f)).ToString() + " kb.";
                                }
                                else
                                {
                                    ms.Position = 0;
                                    try
                                    {
                                        using (Image Img = Image.FromStream(ms))
                                        {
                                            Bitmap Bmp = Img as Bitmap;
                                            if (Bmp != null)
                                            {
                                                ImgData[5] = Bmp.PixelFormat.ToString() + "bpp";
                                            }
                                            ImgData[2] = Img.Width;
                                            ImgData[3] = Img.Height;
                                        }
                                    }
                                    catch (Exception)
                                    {
                                        ImgData[2] = -1;
                                        ImgData[3] = -1;
                                        ImgData[5] = null;
                                        ImgData[8] = null;
    
                                    }
                                }
                            }
    
    
                            ImageDataTable.Rows.Add(ImgData);
                        }
                    }
    
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error");
                    dataGrid.CaptionText = "No file selected";
                    CurrentFilename = null;
                    return;
                }
                dataGrid.CaptionText = "Selected file: " + FileName;
                CurrentRowChanged(GetCurrencyManager, null);
            }
    
            private void FilesListBox_SelectedIndexChanged(object sender, System.EventArgs e)
            {
                TImageInfo ImageInfo = (TImageInfo)FilesListBox.SelectedItem;
                if (ImageInfo == null) return;
                OpenFile(ImageInfo.File.FullName);
            }
    
            public void CurrentRowChanged(object sender, System.EventArgs e)
            {
                int Pos = ((BindingManagerBase)sender).Position;
                if (Pos < 0)
                {
                    PreviewBox.Image = null;
                    return;
                }
    
                DataRowCollection r = dataSet1.Tables["ImageDataTable"].Rows;
                if (Pos < 0 || Pos >= r.Count)
                {
                    PreviewBox.Image = null;
                }
                else
                {
                    byte[] ImgData = r[Pos].ItemArray[8] as byte[];
                    if (ImgData == null)
                    {
                        PreviewBox.Image = null;
                    }
                    else
                    {
                        using (MemoryStream ms = new MemoryStream(ImgData))
                        {
                            PreviewBox.Image = Image.FromStream(ms);
                        }
                    }
                }
            }
    
            private void btnOpen_Click(object sender, System.EventArgs e)
            {
                if (CurrentFilename == null)
                {
                    MessageBox.Show("There is no open file");
                    return;
                }
                using (Process p = new Process())
                {               
                    p.StartInfo.FileName = CurrentFilename;
                    p.StartInfo.UseShellExecute = true;
                    p.Start();
                }              
            }
    
            private void btnConvert_Click(object sender, System.EventArgs e)
            {
                //This is not yet implemented...
                int Pos = GetImagePos;
                if (Pos < 0)
                {
                    MessageBox.Show("There is no selected image", "Error");
                    return;
                }
                if (CompressForm == null) CompressForm = new TCompressForm();
                CompressForm.ImageToUse = (byte[])dataSet1.Tables["ImageDataTable"].Rows[Pos].ItemArray[8];
                CompressForm.XlsFilename = CurrentFilename;
                CompressForm.ShowDialog();
            }
    
            private void FilesListBox_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
            {
                if (e.Index < 0) return;
                e.DrawBackground();
                Brush myBrush = Brushes.Black;
    
                TImageInfo ImageInfo = (TImageInfo)((ListBox)sender).Items[e.Index];
                if (!ImageInfo.HasImages)
                {
                    myBrush = Brushes.Silver;
                }
                if (ImageInfo.HasCrop)
                {
                    myBrush = Brushes.Red;
                }
    
                FontStyle NewStyle;
                if (ImageInfo.HasARGB) NewStyle = FontStyle.Bold; else NewStyle = FontStyle.Regular;
                using (Font MyFont = new Font(e.Font, NewStyle))
                {
                    e.Graphics.DrawString(ImageInfo.ToString(),
                        MyFont, myBrush, e.Bounds, StringFormat.GenericDefault);
                }
                e.DrawFocusRectangle();
            }
    
            private void btnSaveImage_Click(object sender, System.EventArgs e)
            {
                int Pos = GetImagePos;
                if (Pos < 0)
                {
                    MessageBox.Show("There is no selected image to save", "Error");
                    return;
                }
    
                string ext = dataSet1.Tables["ImageDataTable"].Rows[Pos].ItemArray[4].ToString().ToLower();
                saveImageDialog.DefaultExt = ext;
                saveImageDialog.Filter = ext + " Images|*." + ext;
                if (saveImageDialog.ShowDialog() != DialogResult.OK) return;
                byte[] ImgData = (byte[])dataSet1.Tables["ImageDataTable"].Rows[Pos].ItemArray[8];
                using (FileStream fs = new FileStream(saveImageDialog.FileName, FileMode.Create))
                {
                    fs.Write(ImgData, 0, ImgData.Length);
                }
    
            }
    
            private void btnInfo_Click(object sender, System.EventArgs e)
            {
                MessageBox.Show("FlexCelImageExplorer is a small application targeted to reduce the size on images inside Excel files.\n" +
                    "On the current version you can see the image properties and extract the images to disk.");
    
            }
    
            private void btnStretchPreview_Click(object sender, EventArgs e)
            {
                if (btnStretchPreview.Checked)
                    PreviewBox.SizeMode = PictureBoxSizeMode.StretchImage;
                else
                    PreviewBox.SizeMode = PictureBoxSizeMode.Normal;
            }
    
        }
    
        class TImageInfo
        {
            internal FileInfo File;
            internal bool IsValidFile;
            internal bool HasCrop;
            internal bool HasImages;
            internal bool HasARGB;
    
            public TImageInfo(FileInfo aFile, bool aIsValidFile, bool aHasCrop, bool aHasImages, bool aHasARGB)
            {
                File = aFile;
                HasCrop = aHasCrop;
                HasImages = aHasImages;
                IsValidFile = aIsValidFile;
                HasARGB = aHasARGB;
            }
    
            public override string ToString()
            {
                if (!IsValidFile)
                    return " (*)" + File.ToString();
                return File.ToString();
            }
    
        }
    }
    

    MainForm.Designer.cs

    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;
    using System.IO;
    using FlexCel.Core;
    using FlexCel.XlsAdapter;
    namespace FlexCelImageExplorer
    {
        public partial class mainForm: System.Windows.Forms.Form
        {
            private System.Windows.Forms.OpenFileDialog openFileDialog1;
            private System.Windows.Forms.Panel panel1;
            private System.Windows.Forms.Splitter splitter1;
            private System.Windows.Forms.Panel panel3;
            private System.Windows.Forms.ListBox FilesListBox;
            private System.Windows.Forms.Label lblFolder;
            private System.Windows.Forms.DataGrid dataGrid;
            private System.Data.DataSet dataSet1;
            private System.Data.DataTable ImageDataTable;
            private System.Data.DataColumn Index;
            private System.Data.DataColumn Cell1;
            private System.Data.DataColumn Cell2;
            private System.Data.DataColumn cType;
            private System.Data.DataColumn cText;
            private System.Data.DataColumn Description;
            private System.Data.DataColumn dataColumn1;
            private System.Windows.Forms.Panel panel4;
            private System.Windows.Forms.Splitter splitter2;
            private System.Data.DataColumn dataColumn2;
            private System.Windows.Forms.PictureBox PreviewBox;
            private System.Data.DataColumn dataColumn3;
            private System.Windows.Forms.SaveFileDialog saveImageDialog;
            private System.Data.DataColumn dataColumn4;
            private System.ComponentModel.IContainer components = null;
    
            /// <summary>
            /// Clean up any resources being used.
            /// </summary>
            protected override void Dispose(bool disposing)
            {
                if (disposing)
                {
                    if (components != null)
                    {
                        components.Dispose();
                    }
                }
                base.Dispose(disposing);
            }
    
            #region Windows Form Designer generated code
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InitializeComponent()
            {
                System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(mainForm));
                this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
                this.panel1 = new System.Windows.Forms.Panel();
                this.FilesListBox = new System.Windows.Forms.ListBox();
                this.panel3 = new System.Windows.Forms.Panel();
                this.lblFolder = new System.Windows.Forms.Label();
                this.splitter1 = new System.Windows.Forms.Splitter();
                this.dataGrid = new System.Windows.Forms.DataGrid();
                this.ImageDataTable = new System.Data.DataTable();
                this.dataColumn4 = new System.Data.DataColumn();
                this.Index = new System.Data.DataColumn();
                this.Cell1 = new System.Data.DataColumn();
                this.Cell2 = new System.Data.DataColumn();
                this.cType = new System.Data.DataColumn();
                this.cText = new System.Data.DataColumn();
                this.Description = new System.Data.DataColumn();
                this.dataColumn1 = new System.Data.DataColumn();
                this.dataColumn2 = new System.Data.DataColumn();
                this.dataColumn3 = new System.Data.DataColumn();
                this.dataSet1 = new System.Data.DataSet();
                this.panel4 = new System.Windows.Forms.Panel();
                this.PreviewBox = new System.Windows.Forms.PictureBox();
                this.splitter2 = new System.Windows.Forms.Splitter();
                this.saveImageDialog = new System.Windows.Forms.SaveFileDialog();
                this.mainToolbar = new System.Windows.Forms.ToolStrip();
                this.cbScanFolder = new System.Windows.Forms.ToolStripButton();
                this.btnOpenFile = new System.Windows.Forms.ToolStripButton();
                this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
                this.btnShowInExcel = new System.Windows.Forms.ToolStripButton();
                this.btnSaveAsImage = new System.Windows.Forms.ToolStripButton();
                this.btnExit = new System.Windows.Forms.ToolStripButton();
                this.btnInfo = new System.Windows.Forms.ToolStripButton();
                this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
                this.btnStretchPreview = new System.Windows.Forms.ToolStripButton();
                this.panel1.SuspendLayout();
                this.panel3.SuspendLayout();
                ((System.ComponentModel.ISupportInitialize)(this.dataGrid)).BeginInit();
                ((System.ComponentModel.ISupportInitialize)(this.ImageDataTable)).BeginInit();
                ((System.ComponentModel.ISupportInitialize)(this.dataSet1)).BeginInit();
                this.panel4.SuspendLayout();
                ((System.ComponentModel.ISupportInitialize)(this.PreviewBox)).BeginInit();
                this.mainToolbar.SuspendLayout();
                this.SuspendLayout();
                // 
                // openFileDialog1
                // 
                this.openFileDialog1.DefaultExt = "xls";
                this.openFileDialog1.Filter = "Excel Files|*.xls;*.xlsx;*.xlsm|Excel 97/2003|*.xls|Excel 2007|*.xlsx;*.xlsm|All " +
        "files|*.*";
                this.openFileDialog1.Title = "Open an Excel File";
                // 
                // panel1
                // 
                this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
                this.panel1.Controls.Add(this.FilesListBox);
                this.panel1.Controls.Add(this.panel3);
                this.panel1.Dock = System.Windows.Forms.DockStyle.Left;
                this.panel1.Location = new System.Drawing.Point(0, 38);
                this.panel1.Name = "panel1";
                this.panel1.Size = new System.Drawing.Size(176, 400);
                this.panel1.TabIndex = 4;
                // 
                // FilesListBox
                // 
                this.FilesListBox.Dock = System.Windows.Forms.DockStyle.Fill;
                this.FilesListBox.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
                this.FilesListBox.Location = new System.Drawing.Point(0, 40);
                this.FilesListBox.Name = "FilesListBox";
                this.FilesListBox.Size = new System.Drawing.Size(172, 356);
                this.FilesListBox.TabIndex = 1;
                this.FilesListBox.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.FilesListBox_DrawItem);
                this.FilesListBox.SelectedIndexChanged += new System.EventHandler(this.FilesListBox_SelectedIndexChanged);
                // 
                // panel3
                // 
                this.panel3.BackColor = System.Drawing.Color.DarkSeaGreen;
                this.panel3.Controls.Add(this.lblFolder);
                this.panel3.Dock = System.Windows.Forms.DockStyle.Top;
                this.panel3.Location = new System.Drawing.Point(0, 0);
                this.panel3.Name = "panel3";
                this.panel3.Size = new System.Drawing.Size(172, 40);
                this.panel3.TabIndex = 0;
                // 
                // lblFolder
                // 
                this.lblFolder.Dock = System.Windows.Forms.DockStyle.Fill;
                this.lblFolder.ForeColor = System.Drawing.Color.Black;
                this.lblFolder.Location = new System.Drawing.Point(0, 0);
                this.lblFolder.Name = "lblFolder";
                this.lblFolder.Size = new System.Drawing.Size(172, 40);
                this.lblFolder.TabIndex = 0;
                this.lblFolder.Text = "No Selected Folder.";
                // 
                // splitter1
                // 
                this.splitter1.Location = new System.Drawing.Point(176, 38);
                this.splitter1.Name = "splitter1";
                this.splitter1.Size = new System.Drawing.Size(3, 400);
                this.splitter1.TabIndex = 5;
                this.splitter1.TabStop = false;
                // 
                // dataGrid
                // 
                this.dataGrid.CaptionText = "No file selected";
                this.dataGrid.DataMember = "";
                this.dataGrid.DataSource = this.ImageDataTable;
                this.dataGrid.Dock = System.Windows.Forms.DockStyle.Top;
                this.dataGrid.HeaderForeColor = System.Drawing.SystemColors.ControlText;
                this.dataGrid.Location = new System.Drawing.Point(179, 38);
                this.dataGrid.Name = "dataGrid";
                this.dataGrid.PreferredColumnWidth = 120;
                this.dataGrid.ReadOnly = true;
                this.dataGrid.Size = new System.Drawing.Size(709, 128);
                this.dataGrid.TabIndex = 7;
                // 
                // ImageDataTable
                // 
                this.ImageDataTable.Columns.AddRange(new System.Data.DataColumn[] {
                this.dataColumn4,
                this.Index,
                this.Cell1,
                this.Cell2,
                this.cType,
                this.cText,
                this.Description,
                this.dataColumn1,
                this.dataColumn2,
                this.dataColumn3});
                this.ImageDataTable.TableName = "ImageDataTable";
                // 
                // dataColumn4
                // 
                this.dataColumn4.ColumnName = "Sheet";
                // 
                // Index
                // 
                this.Index.ColumnName = "Index";
                // 
                // Cell1
                // 
                this.Cell1.Caption = "Width (Pixels)";
                this.Cell1.ColumnName = "Width (Pixels)";
                // 
                // Cell2
                // 
                this.Cell2.Caption = "Height (Pixels)";
                this.Cell2.ColumnName = "Height (Pixels)";
                // 
                // cType
                // 
                this.cType.ColumnName = "Type";
                // 
                // cText
                // 
                this.cText.Caption = "Image Format";
                this.cText.ColumnName = "Image Format";
                // 
                // Description
                // 
                this.Description.Caption = "Uncompressed size";
                this.Description.ColumnName = "Uncompressed size";
                // 
                // dataColumn1
                // 
                this.dataColumn1.Caption = "Name";
                this.dataColumn1.ColumnName = "Name";
                // 
                // dataColumn2
                // 
                this.dataColumn2.ColumnMapping = System.Data.MappingType.Hidden;
                this.dataColumn2.ColumnName = "Image";
                this.dataColumn2.DataType = typeof(byte[]);
                // 
                // dataColumn3
                // 
                this.dataColumn3.ColumnName = "Cropped";
                this.dataColumn3.DataType = typeof(bool);
                // 
                // dataSet1
                // 
                this.dataSet1.DataSetName = "ImageDataSet";
                this.dataSet1.Locale = new System.Globalization.CultureInfo("");
                this.dataSet1.Tables.AddRange(new System.Data.DataTable[] {
                this.ImageDataTable});
                // 
                // panel4
                // 
                this.panel4.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
                this.panel4.Controls.Add(this.PreviewBox);
                this.panel4.Dock = System.Windows.Forms.DockStyle.Fill;
                this.panel4.Location = new System.Drawing.Point(179, 169);
                this.panel4.Name = "panel4";
                this.panel4.Size = new System.Drawing.Size(709, 269);
                this.panel4.TabIndex = 8;
                // 
                // PreviewBox
                // 
                this.PreviewBox.Dock = System.Windows.Forms.DockStyle.Fill;
                this.PreviewBox.Location = new System.Drawing.Point(0, 0);
                this.PreviewBox.Name = "PreviewBox";
                this.PreviewBox.Size = new System.Drawing.Size(705, 265);
                this.PreviewBox.TabIndex = 0;
                this.PreviewBox.TabStop = false;
                // 
                // splitter2
                // 
                this.splitter2.Dock = System.Windows.Forms.DockStyle.Top;
                this.splitter2.Location = new System.Drawing.Point(179, 166);
                this.splitter2.Name = "splitter2";
                this.splitter2.Size = new System.Drawing.Size(709, 3);
                this.splitter2.TabIndex = 9;
                this.splitter2.TabStop = false;
                // 
                // mainToolbar
                // 
                this.mainToolbar.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
                this.cbScanFolder,
                this.btnOpenFile,
                this.toolStripSeparator1,
                this.btnShowInExcel,
                this.btnSaveAsImage,
                this.btnExit,
                this.btnInfo,
                this.toolStripSeparator2,
                this.btnStretchPreview});
                this.mainToolbar.Location = new System.Drawing.Point(0, 0);
                this.mainToolbar.Name = "mainToolbar";
                this.mainToolbar.Size = new System.Drawing.Size(888, 38);
                this.mainToolbar.TabIndex = 12;
                this.mainToolbar.Text = "toolStrip1";
                // 
                // cbScanFolder
                // 
                this.cbScanFolder.CheckOnClick = true;
                this.cbScanFolder.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
                this.cbScanFolder.Image = ((System.Drawing.Image)(resources.GetObject("cbScanFolder.Image")));
                this.cbScanFolder.ImageTransparentColor = System.Drawing.Color.Magenta;
                this.cbScanFolder.Name = "cbScanFolder";
                this.cbScanFolder.Size = new System.Drawing.Size(122, 35);
                this.cbScanFolder.Text = "Scan all files in folder";
                this.cbScanFolder.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageAboveText;
                // 
                // btnOpenFile
                // 
                this.btnOpenFile.Image = ((System.Drawing.Image)(resources.GetObject("btnOpenFile.Image")));
                this.btnOpenFile.ImageTransparentColor = System.Drawing.Color.Magenta;
                this.btnOpenFile.Name = "btnOpenFile";
                this.btnOpenFile.Size = new System.Drawing.Size(59, 35);
                this.btnOpenFile.Text = "Open file";
                this.btnOpenFile.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageAboveText;
                this.btnOpenFile.Click += new System.EventHandler(this.btnOpenFile_Click);
                // 
                // toolStripSeparator1
                // 
                this.toolStripSeparator1.Name = "toolStripSeparator1";
                this.toolStripSeparator1.Size = new System.Drawing.Size(6, 38);
                // 
                // btnShowInExcel
                // 
                this.btnShowInExcel.Image = ((System.Drawing.Image)(resources.GetObject("btnShowInExcel.Image")));
                this.btnShowInExcel.ImageTransparentColor = System.Drawing.Color.Magenta;
                this.btnShowInExcel.Name = "btnShowInExcel";
                this.btnShowInExcel.Size = new System.Drawing.Size(82, 35);
                this.btnShowInExcel.Text = "Show in Excel";
                this.btnShowInExcel.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageAboveText;
                this.btnShowInExcel.Click += new System.EventHandler(this.btnOpen_Click);
                // 
                // btnSaveAsImage
                // 
                this.btnSaveAsImage.Image = ((System.Drawing.Image)(resources.GetObject("btnSaveAsImage.Image")));
                this.btnSaveAsImage.ImageTransparentColor = System.Drawing.Color.Magenta;
                this.btnSaveAsImage.Name = "btnSaveAsImage";
                this.btnSaveAsImage.Size = new System.Drawing.Size(85, 35);
                this.btnSaveAsImage.Text = "Save as image";
                this.btnSaveAsImage.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageAboveText;
                this.btnSaveAsImage.Click += new System.EventHandler(this.btnSaveImage_Click);
                // 
                // btnExit
                // 
                this.btnExit.Alignment = System.Windows.Forms.ToolStripItemAlignment.Right;
                this.btnExit.Image = ((System.Drawing.Image)(resources.GetObject("btnExit.Image")));
                this.btnExit.ImageTransparentColor = System.Drawing.Color.Magenta;
                this.btnExit.Name = "btnExit";
                this.btnExit.Size = new System.Drawing.Size(59, 35);
                this.btnExit.Text = "     E&xit     ";
                this.btnExit.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageAboveText;
                this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
                // 
                // btnInfo
                // 
                this.btnInfo.Alignment = System.Windows.Forms.ToolStripItemAlignment.Right;
                this.btnInfo.Image = ((System.Drawing.Image)(resources.GetObject("btnInfo.Image")));
                this.btnInfo.ImageTransparentColor = System.Drawing.Color.Magenta;
                this.btnInfo.Name = "btnInfo";
                this.btnInfo.Size = new System.Drawing.Size(74, 35);
                this.btnInfo.Text = "Information";
                this.btnInfo.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageAboveText;
                this.btnInfo.Click += new System.EventHandler(this.btnInfo_Click);
                // 
                // toolStripSeparator2
                // 
                this.toolStripSeparator2.Name = "toolStripSeparator2";
                this.toolStripSeparator2.Size = new System.Drawing.Size(6, 38);
                // 
                // btnStretchPreview
                // 
                this.btnStretchPreview.CheckOnClick = true;
                this.btnStretchPreview.Image = ((System.Drawing.Image)(resources.GetObject("btnStretchPreview.Image")));
                this.btnStretchPreview.ImageTransparentColor = System.Drawing.Color.Magenta;
                this.btnStretchPreview.Name = "btnStretchPreview";
                this.btnStretchPreview.Size = new System.Drawing.Size(92, 35);
                this.btnStretchPreview.Text = "Stretch preview";
                this.btnStretchPreview.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageAboveText;
                this.btnStretchPreview.Click += new System.EventHandler(this.btnStretchPreview_Click);
                // 
                // mainForm
                // 
                this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
                this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                this.ClientSize = new System.Drawing.Size(888, 438);
                this.Controls.Add(this.panel4);
                this.Controls.Add(this.splitter2);
                this.Controls.Add(this.dataGrid);
                this.Controls.Add(this.splitter1);
                this.Controls.Add(this.panel1);
                this.Controls.Add(this.mainToolbar);
                this.Name = "mainForm";
                this.Text = "FlexCel Image Explorer";
                this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
                this.panel1.ResumeLayout(false);
                this.panel3.ResumeLayout(false);
                ((System.ComponentModel.ISupportInitialize)(this.dataGrid)).EndInit();
                ((System.ComponentModel.ISupportInitialize)(this.ImageDataTable)).EndInit();
                ((System.ComponentModel.ISupportInitialize)(this.dataSet1)).EndInit();
                this.panel4.ResumeLayout(false);
                ((System.ComponentModel.ISupportInitialize)(this.PreviewBox)).EndInit();
                this.mainToolbar.ResumeLayout(false);
                this.mainToolbar.PerformLayout();
                this.ResumeLayout(false);
                this.PerformLayout();
    
            }
            #endregion
    
            private ToolStrip mainToolbar;
            private ToolStripButton btnOpenFile;
            private ToolStripSeparator toolStripSeparator1;
            private ToolStripButton btnShowInExcel;
            private ToolStripButton btnSaveAsImage;
            private ToolStripButton btnExit;
            private ToolStripButton btnInfo;
            private ToolStripSeparator toolStripSeparator2;
            private ToolStripButton btnStretchPreview;
            private ToolStripButton cbScanFolder;
        }
    }
    

    Program.cs

    using System;
    using System.Windows.Forms;
    
    namespace FlexCelImageExplorer
    {
        static class Program
        {
            /// <summary>
            /// The main entry point for the application.
            /// </summary>
            [STAThread]
            static void Main()
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new mainForm());
            }
        }
    }
    

    TCompressForm.cs

    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.IO;
    
    namespace FlexCelImageExplorer
    {
        /// <summary>
        /// Summary description for TCompressForm.
        /// </summary>
        public partial class TCompressForm: System.Windows.Forms.Form
        {
    
            public TCompressForm()
            {
                //
                // Required for Windows Form Designer support
                //
                InitializeComponent();
                cbPixelFormat.SelectedIndex = 2;
    
                //
                // TODO: Add any constructor code after InitializeComponent call
                //
            }
    
            private byte[] FImageToUse;
            private string FXlsFilename;
    
            internal byte[] ImageToUse
            {
                get
                {
                    return FImageToUse;
                }
                set
                {
                    FImageToUse = value;
                    using (MemoryStream ms = new MemoryStream(value))
                    {
                        pictureBox1.Image = Image.FromStream(ms);
                    }
                }
            }
    
            internal string XlsFilename
            {
                get
                {
                    return FXlsFilename;
                }
                set
                {
                    FXlsFilename = value;
                }
            }
    
            private void btnCancel_Click(object sender, System.EventArgs e)
            {
                Close();
            }
    
            private void TCompressForm_Load(object sender, System.EventArgs e)
            {
            }
    
            private void btnOk_Click(object sender, System.EventArgs e)
            {
                Close();
            }
        }
    }
    

    TCompressForm.Designer.cs

    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.IO;
    namespace FlexCelImageExplorer
    {
        public partial class TCompressForm: System.Windows.Forms.Form
        {
            private System.Windows.Forms.Label label1;
            private System.Windows.Forms.NumericUpDown edPercent;
            private System.Windows.Forms.ComboBox cbPixelFormat;
            private System.Windows.Forms.Button btnOk;
            private System.Windows.Forms.Button btnCancel;
            private System.Windows.Forms.Panel panel1;
            private System.Windows.Forms.Panel panel2;
            private System.Windows.Forms.PictureBox pictureBox1;
            private System.Windows.Forms.CheckBox cbTransparent;
            /// <summary>
            /// Required designer variable.
            /// </summary>
            private System.ComponentModel.Container components = null;
    
            /// <summary>
            /// Clean up any resources being used.
            /// </summary>
            protected override void Dispose(bool disposing)
            {
                if (disposing)
                {
                    if (components != null)
                    {
                        components.Dispose();
                    }
                }
                base.Dispose(disposing);
            }
    
            #region Windows Form Designer generated code
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InitializeComponent()
            {
                this.label1 = new System.Windows.Forms.Label();
                this.edPercent = new System.Windows.Forms.NumericUpDown();
                this.cbPixelFormat = new System.Windows.Forms.ComboBox();
                this.btnOk = new System.Windows.Forms.Button();
                this.btnCancel = new System.Windows.Forms.Button();
                this.panel1 = new System.Windows.Forms.Panel();
                this.panel2 = new System.Windows.Forms.Panel();
                this.pictureBox1 = new System.Windows.Forms.PictureBox();
                this.cbTransparent = new System.Windows.Forms.CheckBox();
                ((System.ComponentModel.ISupportInitialize)(this.edPercent)).BeginInit();
                this.panel1.SuspendLayout();
                this.panel2.SuspendLayout();
                this.SuspendLayout();
                // 
                // label1
                // 
                this.label1.Location = new System.Drawing.Point(16, 8);
                this.label1.Name = "label1";
                this.label1.Size = new System.Drawing.Size(144, 16);
                this.label1.TabIndex = 0;
                this.label1.Text = "Change Resolution (%):";
                // 
                // edPercent
                // 
                this.edPercent.Increment = new System.Decimal(new int[] {
                                                                            5,
                                                                            0,
                                                                            0,
                                                                            0});
                this.edPercent.Location = new System.Drawing.Point(176, 8);
                this.edPercent.Minimum = new System.Decimal(new int[] {
                                                                          10,
                                                                          0,
                                                                          0,
                                                                          0});
                this.edPercent.Name = "edPercent";
                this.edPercent.Size = new System.Drawing.Size(48, 20);
                this.edPercent.TabIndex = 2;
                this.edPercent.Value = new System.Decimal(new int[] {
                                                                        60,
                                                                        0,
                                                                        0,
                                                                        0});
                // 
                // cbPixelFormat
                // 
                this.cbPixelFormat.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
                this.cbPixelFormat.Items.AddRange(new object[] {
                                                                   "1bpp (Black and White)",
                                                                   "8bpp (256 colors optimized palette)",
                                                                   "24bpp (true color)"});
                this.cbPixelFormat.Location = new System.Drawing.Point(16, 40);
                this.cbPixelFormat.Name = "cbPixelFormat";
                this.cbPixelFormat.Size = new System.Drawing.Size(208, 21);
                this.cbPixelFormat.TabIndex = 3;
                // 
                // btnOk
                // 
                this.btnOk.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
                this.btnOk.FlatStyle = System.Windows.Forms.FlatStyle.System;
                this.btnOk.Location = new System.Drawing.Point(148, 168);
                this.btnOk.Name = "btnOk";
                this.btnOk.TabIndex = 4;
                this.btnOk.Text = "Ok";
                this.btnOk.Click += new System.EventHandler(this.btnOk_Click);
                // 
                // btnCancel
                // 
                this.btnCancel.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
                this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
                this.btnCancel.FlatStyle = System.Windows.Forms.FlatStyle.System;
                this.btnCancel.Location = new System.Drawing.Point(244, 168);
                this.btnCancel.Name = "btnCancel";
                this.btnCancel.TabIndex = 5;
                this.btnCancel.Text = "Cancel";
                this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
                // 
                // panel1
                // 
                this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
                this.panel1.Controls.Add(this.cbTransparent);
                this.panel1.Controls.Add(this.edPercent);
                this.panel1.Controls.Add(this.cbPixelFormat);
                this.panel1.Controls.Add(this.label1);
                this.panel1.Location = new System.Drawing.Point(16, 16);
                this.panel1.Name = "panel1";
                this.panel1.Size = new System.Drawing.Size(240, 136);
                this.panel1.TabIndex = 6;
                // 
                // panel2
                // 
                this.panel2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                    | System.Windows.Forms.AnchorStyles.Left)
                    | System.Windows.Forms.AnchorStyles.Right)));
                this.panel2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
                this.panel2.Controls.Add(this.pictureBox1);
                this.panel2.Location = new System.Drawing.Point(280, 16);
                this.panel2.Name = "panel2";
                this.panel2.Size = new System.Drawing.Size(168, 136);
                this.panel2.TabIndex = 7;
                // 
                // pictureBox1
                // 
                this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Fill;
                this.pictureBox1.Location = new System.Drawing.Point(0, 0);
                this.pictureBox1.Name = "pictureBox1";
                this.pictureBox1.Size = new System.Drawing.Size(164, 132);
                this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
                this.pictureBox1.TabIndex = 0;
                this.pictureBox1.TabStop = false;
                // 
                // cbTransparent
                // 
                this.cbTransparent.Location = new System.Drawing.Point(16, 88);
                this.cbTransparent.Name = "cbTransparent";
                this.cbTransparent.TabIndex = 4;
                this.cbTransparent.Text = "Transparent";
                // 
                // TCompressForm
                // 
                this.AcceptButton = this.btnOk;
                this.CancelButton = this.btnCancel;
                this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
                this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                this.ClientSize = new System.Drawing.Size(472, 214);
                this.Controls.Add(this.panel2);
                this.Controls.Add(this.panel1);
                this.Controls.Add(this.btnCancel);
                this.Controls.Add(this.btnOk);
                this.Name = "TCompressForm";
                this.Text = "Compression Options...";
                this.Load += new System.EventHandler(this.TCompressForm_Load);
                ((System.ComponentModel.ISupportInitialize)(this.edPercent)).EndInit();
                this.panel1.ResumeLayout(false);
                this.panel2.ResumeLayout(false);
                this.ResumeLayout(false);
    
            }
            #endregion
        }
    }
    
    In This Article
    Back to top FlexCel Studio for the .NET Framework v7.24.0.0
    © 2002 - 2025 tmssoftware.com