Пример #1
0
        /// <summary>
        /// Helper method that applies any pixel changes between the image version and the latest version
        /// </summary>
        /// <param name="canvas">Which canvas to apply changes to</param>
        private void ApplyChangedPixelsToImage(CanvasImage canvasImage)
        {
            Canvas canvas = canvasImage.canvas;

            // Get changed pixels
            IEnumerable <PixelChange> pixelChanges = databaseContext.PixelChanges
                                                     .Where(p => p.CanvasVersion > canvas.ImageVersion && p.Canvas.Name == canvas.Name)
                                                     .OrderBy(p => p.CanvasVersion);

            if (!pixelChanges.Any())
            {
                return;
            }

            // Update bitmap with changes
            Bitmap bitmap = canvasImage.GetBitmap();

            foreach (PixelChange pixelChange in pixelChanges)
            {
                bitmap.SetPixel(pixelChange.X, pixelChange.Y, ColorTranslator.FromHtml(pixelChange.Color));
                //placeContext.PixelChanges.Remove(pixelChange);
            }

            canvasImage.SetBitmap(bitmap);

            canvas.ImageVersion = pixelChanges.Last().CanvasVersion;
            databaseContext.SaveChanges();
        }