Exemple #1
0
        /// <summary>
        /// Creates a <see cref="BitmapImage"/> from the stored <see cref="Dna"/> and stores it on the <see cref="IDnaRendererUtility"/>.
        /// </summary>
        /// <param name="width">Width of the <see cref="BitmapImage"/>.</param>
        /// <param name="height">Height of the <see cref="BitmapImage"/>.</param>
        /// <param name="renderer">The renderer to create the <see cref="BitmapImage"/> with.</param>
        public void CreateBitmapImage(int width, int height, IDnaRendererUtility renderer)
        {
            if (renderer == null)
            {
                throw new ArgumentNullException(nameof(renderer));
            }

            renderer.Image = Render(width, height, renderer).ToBitmapImage();
        }
Exemple #2
0
        // Renders the image of a given size to a writeable bitmap.
        private WriteableBitmap Render(int width, int height, IDnaRendererUtility renderer)
        {
            var writeableBitmap = new WriteableBitmap(width, height, 300, 300, PixelFormats.Rgb24, null);

            if (this.dnaSource == null)
            {
                return(writeableBitmap);
            }

            renderer.CreateImage(writeableBitmap, this.dnaSource);

            return(writeableBitmap);
        }
Exemple #3
0
        /// <summary>
        /// Renders the stored <see cref="Dna"/> with the given <see cref="IDnaRendererUtility"/>.
        /// </summary>
        /// <param name="renderer">The renderer to create the image with.</param>
        /// <returns>The location of the image.</returns>
        public string RenderImage(IDnaRendererUtility renderer)
        {
            if (renderer == null)
            {
                return(errorImageLocation);
            }

            this.dnaBitmapRenderer.CreateBitmapImage(this.renderWidth, this.renderHeight, renderer);

            if (renderer.Image == null)
            {
                return(errorImageLocation);
            }

            return(renderer.SaveToFile(saveLocation));
        }
        /// <summary>
        /// Saves the image stores on the <see cref="IDnaRendererUtility"/> to the given save path.
        /// </summary>
        /// <param name="renderer">The renderer that produced an image.</param>
        /// <param name="savePath">The path to save the file to.</param>
        /// <returns></returns>
        public static string SaveToFile(this IDnaRendererUtility renderer, string savePath)
        {
            const string fileType     = ".jpg";
            var          encoder      = new JpegBitmapEncoder();
            var          saveLocation = Path.Combine(savePath, renderer.Name);

            // TODO fix this hack to get a unique file.
            if (File.Exists(saveLocation + fileType))
            {
                saveLocation += Guid.NewGuid().ToString();
            }

            saveLocation += fileType;

            encoder.Frames.Add(BitmapFrame.Create(renderer.Image));

            using (var filestream = new FileStream(saveLocation, FileMode.OpenOrCreate))
            {
                encoder.Save(filestream);
            }

            return(saveLocation);
        }
Exemple #5
0
 /// <summary>
 /// Renders a bitmap for the selected renderer and sets the image.
 /// </summary>
 public void RenderImage(IDnaRendererUtility renderer)
 {
     this.DnaBitmapImageLocation = ImageManager.Instance.RenderImage(renderer);
 }