Ejemplo n.º 1
0
        //WARNING - This method assumes that all necessary sanity checks for path have been done!
        /// <summary>
        /// 
        /// </summary>
        /// <param name="traversal"></param>
        /// <param name="path"></param>
        /// <param name="format"></param>
        /// <returns>a List of strings with all the names of the image files</returns>
        public static List<string> ExportDeck(DefaultDeckTraversalModel traversal, string path, System.Drawing.Imaging.ImageFormat format, int width, int height, float scale )
        {
            List<string> file_names = new List<string>();
            //Info here:  http://gotdotnet.com/Community/MessageBoard/Thread.aspx?id=27804
            //Iterate over all the slides
            using (Synchronizer.Lock(traversal.SyncRoot)) {
                using (Synchronizer.Lock(traversal.Deck.SyncRoot)) {
                    using (Synchronizer.Lock(traversal.Deck.TableOfContents.SyncRoot)) {
                        //Create the directory, if it doesn't already exist
                        if (!Directory.Exists(path)) {
                            Directory.CreateDirectory(path);
                        }

                        int imageCount = 1;
                        TableOfContentsModel.Entry currentEntry = traversal.Deck.TableOfContents.Entries[0];
                        while (currentEntry != null) {
                            Color background = Color.Transparent;
                            BackgroundTemplate template = null;

                            // Add the background color
                            // First see if there is a Slide BG, if not, try the Deck.  Otherwise, use transparent.
                            using (Synchronizer.Lock(currentEntry.Slide.SyncRoot)) {
                                if (currentEntry.Slide.BackgroundColor != Color.Empty) {
                                    background = currentEntry.Slide.BackgroundColor;
                                }
                                else if (traversal.Deck.DeckBackgroundColor != Color.Empty) {
                                    background = traversal.Deck.DeckBackgroundColor;
                                }
                                if (currentEntry.Slide.BackgroundTemplate != null) {
                                    template = currentEntry.Slide.BackgroundTemplate;
                                }
                                else if (traversal.Deck.DeckBackgroundTemplate != null) {
                                    template = traversal.Deck.DeckBackgroundTemplate;
                                }
                            }

                            // Get the Image
                            Bitmap toExport = DrawSlide(currentEntry, template, background, SheetDisposition.Background | SheetDisposition.Public | SheetDisposition.Student | SheetDisposition.All, width, height, scale );

                            // Format the imageCount
                            string number = "";
                            if (imageCount >= 0 && imageCount < 10) {
                                number = "00" + imageCount;
                            }
                            else if (imageCount >= 10 && imageCount < 100) {
                                number = "0" + imageCount;
                            }
                            else {
                                number = "" + imageCount;
                            }

                            // Get the extension string based on the exported image type
                            string extension = "";
                            if (format == System.Drawing.Imaging.ImageFormat.Bmp) {
                                extension = "bmp";
                            }
                            else if (format == System.Drawing.Imaging.ImageFormat.Emf) {
                                extension = "emf";
                            }
                            else if (format == System.Drawing.Imaging.ImageFormat.Exif) {
                                extension = "exf";
                            }
                            else if (format == System.Drawing.Imaging.ImageFormat.Gif) {
                                extension = "gif";
                            }
                            else if (format == System.Drawing.Imaging.ImageFormat.Icon) {
                                extension = "ico";
                            }
                            else if (format == System.Drawing.Imaging.ImageFormat.Jpeg) {
                                extension = "jpg";
                            }
                            else if (format == System.Drawing.Imaging.ImageFormat.Png) {
                                extension = "png";
                            }
                            else if (format == System.Drawing.Imaging.ImageFormat.Tiff) {
                                extension = "tif";
                            }
                            else if (format == System.Drawing.Imaging.ImageFormat.Wmf) {
                                extension = "wmf";
                            }
                            else {
                                extension = "bmp";
                            }

                            // Construct the complete file name and save
                            string file_name = traversal.Deck.HumanName + "_" + number + "." + extension;
                            //string file_name = "slide" + imageCount.ToString() + "." + extension;
                            toExport.Save(path + "\\" + file_name, format);

                            /// Save the file name to our list
                            file_names.Add(file_name);

                            // Increase the counter
                            imageCount++;

                            // Done, get next entry
                            currentEntry = traversal.FindNext(currentEntry);

                            // Cleanup
                            toExport.Dispose();
                        }
                    }
                }
            }
            return file_names;
        }
Ejemplo n.º 2
0
        //WARNING - This method assumes that all necessary sanity checks for path have been done!
        /// <summary>
        /// 
        /// </summary>
        /// <param name="traversal"></param>
        /// <param name="path"></param>
        /// <param name="format"></param>
        /// <returns>a List of strings with all the names of the image files</returns>
        public static List<string> ExportDeck(DefaultDeckTraversalModel traversal, string path, System.Drawing.Imaging.ImageFormat format)
        {
            List<string> file_names = new List<string>();
            //Info here:  http://gotdotnet.com/Community/MessageBoard/Thread.aspx?id=27804
            //Iterate over all the slides
            using (Synchronizer.Lock(traversal.SyncRoot)) {
                using (Synchronizer.Lock(traversal.Deck.SyncRoot)) {
                    using (Synchronizer.Lock(traversal.Deck.TableOfContents.SyncRoot)) {
                        //Create the directory, if it doesn't already exist
                        if (!Directory.Exists(path)) {
                            Directory.CreateDirectory(path);
                        }

                        int imageCount = 1;
                        TableOfContentsModel.Entry currentEntry = traversal.Deck.TableOfContents.Entries[0];
                        while (currentEntry != null) {
                            Color background = Color.Transparent;

                            // Add the background color
                            // First see if there is a Slide BG, if not, try the Deck.  Otherwise, use transparent.
                            using( Synchronizer.Lock( currentEntry.Slide.SyncRoot ) ) {
                                if( currentEntry.Slide.BackgroundColor != Color.Empty ) {
                                    background = currentEntry.Slide.BackgroundColor;
                                } else if( traversal.Deck.DeckBackgroundColor != Color.Empty ) {
                                    background = traversal.Deck.DeckBackgroundColor;
                                }
                            }

                            // Get the Image
                            Bitmap toExport = DrawSlide( currentEntry, background, SheetDisposition.Background | SheetDisposition.Public | SheetDisposition.Student | SheetDisposition.All );

                            // Format the imageCount
                            string number = "";
                            if( imageCount >= 0 && imageCount < 10 ) {
                                number = "00" + imageCount;
                            } else if( imageCount >= 10 && imageCount < 100 ) {
                                number = "0" + imageCount;
                            } else {
                                number = "" + imageCount;
                            }
                            string file_name = traversal.Deck.HumanName + number + ".jpg";
                            toExport.Save( path + "\\" + file_name, format );

                            /// Save the file name to our list
                            file_names.Add( file_name );

                            imageCount++;

                            // Done, get next entry
                            currentEntry = traversal.FindNext(currentEntry);

                            // Cleanup
                            toExport.Dispose();
                        }
                    }
                }
            }
            return file_names;
        }