public static SlidePreview CreateFromSlide(Slide slide, string presentationId, string text = null) { var preview = new SlidePreview(); preview.slideText = text ?? (slide != null ? ("" + slide.SlideNumber) : "1"); preview.presentationId = presentationId; preview.slideImage = new BitmapImage(); byte[] buffer; if (slide == null || slide.ImageData == null) { var bitmap = new Bitmap(1024, 768); var g = Graphics.FromImage(bitmap); g.Clear(Color.Transparent); using (var memory = new MemoryStream()) { bitmap.Save(memory, ImageFormat.Png); memory.Position = 0; using (var br = new BinaryReader(memory)) { buffer = br.ReadBytes((Int32) memory.Length); } } if (slide != null) slide.ImageData = buffer; } else { buffer = slide.ImageData; } preview.slideImage.BeginInit(); preview.slideImage.StreamSource = new MemoryStream(buffer); preview.slideImage.EndInit(); return preview; }
public bool UpdateSlide(string clientId, string presentationId, Slide slide) { if (string.IsNullOrEmpty(clientId)) return false; if (string.IsNullOrEmpty(presentationId) || !presentations.ContainsKey(presentationId)) return false; if (presentations[presentationId].Owner != clientId) return false; if (presentations[presentationId].Slides == null) return false; if (slide == null) return false; var slides = presentations[presentationId].Slides.ToList(); if (slides.Count <= (slide.SlideNumber - 1)) return false; // update slide slides[slide.SlideNumber - 1] = slide; presentations[presentationId].Slides = slides; return true; }