private static AbstractCompetition LoadPanelCompetition(string competitionFileName, string competitionDirectory, XmlNode rootNode, string clubName, string trophyName, string competitionKey, string resultsKey) { AbstractCompetition competition = new PanelCompetition(competitionFileName, competitionDirectory, clubName, trophyName, competitionKey, resultsKey); XmlNode panelsNode = rootNode["Panels"]; int panelPosition = 1; var panelList = new List <CompetitionPanel>(); foreach (XmlNode eachPanelNode in panelsNode.ChildNodes) { CompetitionPanel eachPanel = new CompetitionPanel(competition, eachPanelNode, panelPosition); int imagePosition = 1; foreach (XmlNode eachImageNode in eachPanelNode.ChildNodes) { CompetitionImage eachImage = new CompetitionImage(competition, eachImageNode, imagePosition); eachPanel.AddImage(eachImage); imagePosition++; } CompetitionFactory.WritePanelLayoutImage(competitionFileName, competitionDirectory, eachPanel); panelList.Add(eachPanel); panelPosition++; } ((PanelCompetition)competition).SetPanels(panelList); return(competition); }
internal static List <CompetitionImage> GetHeldPanels(PanelCompetition competition, string competitionName) { List <CompetitionImage> heldImages = new List <CompetitionImage>(); string databaseFilePath = ImagePaths.GetDatabaseFile(competitionName); SQLiteConnection dbConnection = new SQLiteConnection("DataSource=" + databaseFilePath + ";Version=3;"); dbConnection.Open(); string sql = "SELECT name FROM held_images"; SQLiteCommand cmd = new SQLiteCommand(sql, dbConnection); SQLiteDataReader reader = cmd.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { CompetitionPanel competitionPanel = competition.GetImagePanelById(reader.GetString(0)); heldImages.Add(competitionPanel.GetPanelImage()); } } dbConnection.Close(); return(heldImages); }
private static void WritePanelLayoutImage(string competitionFileName, string competitionDirectory, CompetitionPanel eachPanel) { // Loads the images to tile (no need to specify PngBitmapDecoder, the correct decoder is automatically selected) BitmapFrame frame1 = BitmapDecoder.Create(new Uri(eachPanel.GetImage(0).GetFullFilePath()), BitmapCreateOptions.None, BitmapCacheOption.OnLoad).Frames.First(); BitmapFrame frame2 = BitmapDecoder.Create(new Uri(eachPanel.GetImage(1).GetFullFilePath()), BitmapCreateOptions.None, BitmapCacheOption.OnLoad).Frames.First(); BitmapFrame frame3 = BitmapDecoder.Create(new Uri(eachPanel.GetImage(2).GetFullFilePath()), BitmapCreateOptions.None, BitmapCacheOption.OnLoad).Frames.First(); // Draws the images into a DrawingVisual component DrawingVisual drawingVisual = new DrawingVisual(); using (DrawingContext drawingContext = drawingVisual.RenderOpen()) { drawingContext.DrawImage(frame1, new Rect(0, 0, frame1.PixelWidth, frame1.PixelHeight)); drawingContext.DrawImage(frame2, new Rect(frame1.PixelWidth + 10, 0, frame2.PixelWidth, frame2.PixelHeight)); drawingContext.DrawImage(frame3, new Rect(frame1.PixelWidth + frame2.PixelWidth + 20, 0, frame3.PixelWidth, frame3.PixelHeight)); } // Converts the Visual (DrawingVisual) into a BitmapSource int width = frame1.PixelWidth + frame2.PixelWidth + frame3.PixelWidth + 20; int height = Math.Max(frame1.PixelHeight, Math.Max(frame2.PixelHeight, frame3.PixelHeight)); RenderTargetBitmap bmp = new RenderTargetBitmap(width, height, 96, 96, PixelFormats.Pbgra32); bmp.Render(drawingVisual); // Creates a PngBitmapEncoder and adds the BitmapSource to the frames of the encoder PngBitmapEncoder encoder = new PngBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(bmp)); // Saves the image into a file using the encoder string fileName = eachPanel.GetAuthor() + "_" + eachPanel.GetPosition() + ".jpg"; string filePath = competitionDirectory + "/" + fileName; using (Stream stream = File.Create(filePath)) encoder.Save(stream); }