protected virtual void InitDrawDestination() { drawDestination = this.picOutput.CreateGraphics(); ipHDC = drawDestination.GetHdc(); tmpWorksheet = new Worksheet(); imageMetaFile.Dispose(); imageMetaFile = new Metafile(ipHDC,new Rectangle(0,0,worksheet.GetWorksheetWidth(),worksheet.GetWorksheetHeight()),System.Drawing.Imaging.MetafileFrameUnit.Pixel);//System.Drawing.Imaging.EmfType.EmfPlusDual); // open created empty emf file drawDestination = Graphics.FromImage(imageMetaFile); tmpWorksheet.EnableFootLine = true; tmpWorksheet.Width = worksheet.GetWorksheetWidth(); tmpWorksheet.Height = worksheet.GetWorksheetHeight(); tmpWorksheet.SetMargins(0,0,0,0); tmpWorksheet.EnableFootLine = false; drawDestination.Clear(Color.White); drawDestination.SmoothingMode = imageSmoothingMode; // set image quality drawDestination.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit; }
protected virtual void LoadFile(string filename, bool showInProgram) { string s = String.Empty; string[] temp; temp = filename.Split('\\'); // get filename lastOpenedFile = filename; sourceFileWatch.Path = System.IO.Directory.GetParent(lastOpenedFile).FullName; Worksheet.InitFootLine(); Worksheet tmpWorksheet = new Worksheet(); // create temporary worksheet without margins for screen otput tmpWorksheet.Width = worksheet.GetWorksheetWidth(); tmpWorksheet.Height = worksheet.GetWorksheetHeight(); tmpWorksheet.EnableFootLine = false; tmpWorksheet.SetMargins(0,0,0,0); if (showInProgram == true){ this.stbpFile.Text = temp[temp.Length-1]; Worksheet.FileName = temp[temp.Length - 1]; this.rtbMscEditor.MarkedRow = 0; this.rtbMscEditor.LoadFile(lastOpenedFile,RichTextBoxStreamType.PlainText); this.tlbbSaveText.Enabled = false; this.umnuSave.Enabled = false; } InterpretFile(filename, showInProgram); this.RtbTextInitUndo(); this.rtbMscEditor.Edited = false; this.rtbMscEditor.Modified = false; this.Text = appName + " - " + lastOpenedFile; if (showInProgram == true){ this.ZoomToPage(); this.CenterPage(); } }
protected virtual void ExportImage(string filename, string format) { try { uint pages; Image exportImage = new Bitmap(this.worksheet.Width, this.worksheet.Height); // create export draw area Graphics drawDestination = Graphics.FromImage(exportImage); Graphics grph; IntPtr ipHDC; //necessary for wmf and emf export Metafile mf; //EMetafile ef; pages = GetPages(); // calculate imageBitmap page count if (pages > 0) // something to do? { if (filename.LastIndexOf('.') >= (filename.Length-4)){ filename = filename.Substring(0,filename.LastIndexOf('.')); } for (uint i=1; i<=pages; i++){ switch (format.ToUpper()){ // identify selected format case "BMP": drawDestination.Clear(Color.White); DrawPage(drawDestination,i); exportImage.Save(filename + "_" + i + ".bmp"); break; case "GIF": drawDestination.Clear(Color.White); DrawPage(drawDestination,i); exportImage.Save(filename + "_" + i + ".gif",System.Drawing.Imaging.ImageFormat.Gif); break; case "JPG": drawDestination.Clear(Color.White); DrawPage(drawDestination,i); exportImage.Save(filename + "_" + i + ".jpg",System.Drawing.Imaging.ImageFormat.Jpeg); break; case "PNG": drawDestination.Clear(Color.White); DrawPage(drawDestination,i); exportImage.Save(filename + "_" + i + ".png",System.Drawing.Imaging.ImageFormat.Png); break; case "WMF": drawDestination.Clear(Color.White); exportImage.Save(filename + "_" + i + ".wmf",System.Drawing.Imaging.ImageFormat.Wmf); // for save as wmf first empty wmf file shall be created grph = this.CreateGraphics(); ipHDC = grph.GetHdc(); mf = new Metafile(filename + "_" + i + ".wmf", ipHDC); // open created empty wmf file grph = Graphics.FromImage(mf); grph.Clear(Color.White); grph.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None; // set image quality grph.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit; DrawPage(grph,i); // draw imageBitmap direct to wmf file grph.Dispose(); mf.Dispose(); break; case "EMF": drawDestination.Clear(Color.White); exportImage.Save(filename + "_" + i + ".emf",System.Drawing.Imaging.ImageFormat.Emf); // for save as emf first empty wmf file shall be created grph = this.CreateGraphics(); ipHDC = grph.GetHdc(); mf = new Metafile(filename + "_" + i + ".emf", ipHDC); // open created empty emf file grph = Graphics.FromImage(mf); grph.Clear(Color.White); grph.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None; // set image quality grph.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit; DrawPage(grph,i); // draw imageBitmap direct to emf file grph.Dispose(); mf.Dispose(); break; } } } Worksheet tmpWorksheet = new Worksheet(); // recalculate back line hights for screen output tmpWorksheet.Width = worksheet.GetWorksheetWidth(); tmpWorksheet.Height = worksheet.GetWorksheetHeight(); tmpWorksheet.SetMargins(0,0,0,0); drawDestination.Dispose(); exportImage.Dispose(); } catch(Exception ex) { MessageBox.Show(ex.Message); } }