Пример #1
0
        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);
        }