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); }
/// <summary> /// Draws the graphs for each of the devices. /// </summary> /// <returns>The graphs.</returns> /// <param name="file">File.</param> /// <param name="dlr">Dlr.</param> /// <param name="row">The x coordinate.</param> /// <param name="col">The y coordinate.</param> private Tuple <int, int> DrawGraphs(XlsFile file, DataLogReport dlr, int row, int col) { var l = dlr.localization; var imageCellWidth = 8; var imageCellHeight = 4; var index = 0; foreach (var sensor in dlr.dataLogResults.Keys) { if (!dlr.graphImages.ContainsKey(sensor)) { Log.E(this, "Failed to export sensor graph"); continue; } int xoff = 0, yoff = 0; if (index > 0) { xoff = 1; yoff = 1; } else { xoff = col; yoff = row; } var image = dlr.graphImages[sensor]; file.MergeCells(yoff, xoff, yoff + imageCellHeight, xoff + imageCellWidth); file.SetRowHeight(yoff, (int)(image.height * FlxConsts.RowMult)); TClientAnchor anchor = new TClientAnchor(TFlxAnchorType.MoveAndDontResize, yoff, 0, xoff, 0, yoff + imageCellHeight, 0, xoff + imageCellWidth, 0); double width = 0.0, height = 0.0; anchor.CalcImageCoords(ref height, ref width, file); // Width should always be greater than the height. anchor = new TClientAnchor(TFlxAnchorType.MoveAndDontResize, yoff, 0, xoff, 0, (int)height, (int)width, file); var imageProperties = new TImageProperties(); imageProperties.Anchor = anchor; file.AddImage(image.data, TXlsImgType.Png, imageProperties); index++; file.ActiveSheet++; } return(new Tuple <int, int>(imageCellWidth, index * (imageCellHeight + 1))); }
/// <summary> /// Attempts to draw the Appion logo into the upper left of the file on the current sheet. /// </summary> /// <param name="file">File.</param> /// <returns>A Tuple containing the width and height respectively of the drawn section.</returns> private Tuple <int, int> DrawAppionLogo(XlsFile file, DataLogReport dlr) { if (dlr.appionLogoPng != null) { // Add the image var image = new TImageProperties(); image.Anchor = new TClientAnchor(TFlxAnchorType.MoveAndDontResize, 1, 0, 1, 0, 5, 255, 3, 1024); image.ShapeName = "Logo"; file.AddImage(dlr.appionLogoPng.data, image); // Add the header file.MergeCells(4, 4, 5, 6); file.SetCellValue(4, 4, dlr.reportName, titleFormat); return(new Tuple <int, int>(6, 4)); } else { Log.E(this, "Failed to draw appion logo: no bitmap bytes"); return(new Tuple <int, int>(0, 0)); } }
/// <summary> /// Draws the graphs for each of the devices. /// </summary> /// <returns>The graphs.</returns> /// <param name="file">File.</param> /// <param name="dlr">Dlr.</param> /// <param name="row">The x coordinate.</param> /// <param name="col">The y coordinate.</param> private Tuple <int, int> DrawSmallGraphs(XlsFile file, DataLogReport dlr, int row, int col) { var l = dlr.localization; var imageCellWidth = 4; var imageCellHeight = 3; var index = 0; foreach (var sensor in dlr.dataLogResults.Keys) { if (!dlr.graphImages.ContainsKey(sensor)) { Log.E(this, "Failed to export sensor graph"); continue; } int xoff = 0, yoff = 0; // The shift that is used to stagger the graphs down the pages. xoff = col + (index % 2 == 1 ? imageCellWidth + 1 : 0); yoff = (int)(row + (index / 2 * imageCellHeight)); var image = dlr.graphImages[sensor]; file.MergeCells(yoff, xoff, yoff + imageCellHeight, xoff + imageCellWidth); file.SetRowHeight(yoff, (int)(image.height * FlxConsts.RowMult)); TClientAnchor anchor = new TClientAnchor(TFlxAnchorType.MoveAndDontResize, yoff, 0, xoff, 0, yoff + imageCellHeight, 0, xoff + imageCellWidth, 0); double width = 0.0, height = 0.0; anchor.CalcImageCoords(ref height, ref width, file); // Width should always be greater than the height. anchor = new TClientAnchor(TFlxAnchorType.MoveAndDontResize, yoff, 0, xoff, 0, (int)height, (int)width, file); var imageProperties = new TImageProperties(); imageProperties.Anchor = anchor; file.AddImage(image.data, TXlsImgType.Png, imageProperties); index++; } return(new Tuple <int, int>((imageCellWidth + 1) * 2, (int)Math.Ceiling(index / 2.0) * (imageCellHeight + 1))); }
internal void AddNewComment(int Row, int Col, TRichString Txt, string Author, TDrawing Drawing, TImageProperties Properties, ExcelFile xls, TSheet sSheet, bool ReadFromXlsx) { TNoteRecord R = new TNoteRecord(Row, Col, Txt, Author, Drawing, Properties, xls, sSheet, ReadFromXlsx); //.CreateFromData AddRecord(R, Row); }
/// <summary> /// CreateFromData /// </summary> internal TNoteRecord(int aRow, int aCol, TRichString aTxt, string aAuthor, TDrawing Drawing, TImageProperties Properties, ExcelFile xls, TSheet sSheet, bool ReadFromXlsx) : base((int)xlr.NOTE, aCol) { if ((aCol < 0) || (aCol > FlxConsts.Max_Columns)) { XlsMessages.ThrowException(XlsErr.ErrXlsIndexOutBounds, aCol, "Column", 0, FlxConsts.Max_Columns); } Dwg = Drawing.AddNewComment(xls, Properties, sSheet, ReadFromXlsx); TEscherImageAnchorRecord Anchor = GetImageRecord(); if (Anchor != null) { NoteTextBox = Anchor.SaveCommentCoords(sSheet, aRow, aCol); } Col = aCol; OptionFlags = 0; //option flags unchecked { ObjId = (UInt16)Dwg.ObjId; //object id } Author = aAuthor; SetText(aTxt); }
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); }