GetImageStream() public method

public GetImageStream ( ) : Stream
return Stream
Exemplo n.º 1
0
        /// <summary>
        /// Handles the RunWorkerCompleted event of the renderThread control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.ComponentModel.RunWorkerCompletedEventArgs"/> instance containing the event data.</param>
        private void renderThread_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (e.Cancelled)
            {
                if (enqueueExport != null)                 //cancelled because new image was requested. Create new image
                {
                    GetSource(enqueueExport, enqueueOnComplete);
                    enqueueExport     = null;
                    enqueueOnComplete = null;
                }
                return;
            }
            enqueueExport     = null;
            enqueueOnComplete = null;
            if (e.Result == null)
            {
                return;
            }
            object[] result = (object[])e.Result;

            int             width      = (int)result[1];
            int             height     = (int)result[2];
            Envelope        extent     = (Envelope)result[3];
            OnImageComplete onComplete = (OnImageComplete)result[4];

#if SILVERLIGHT
            BitmapImage image = new BitmapImage();
            PngEncoder  ei    = (PngEncoder)result[0];
            image.SetSource(ei.GetImageStream());
#else
            List <Color> colors = new List <Color>();
            colors.Add(Colors.Violet);
            colors.Add(Colors.Yellow);
            BitmapPalette palette = new BitmapPalette(colors);
            System.Windows.Media.PixelFormat pf =
                System.Windows.Media.PixelFormats.Bgra32;
            int          stride = width * (pf.BitsPerPixel / 8);
            BitmapSource image  = BitmapSource.Create(width, height, 96, 96, pf, palette, (int[])result[0], stride);
#endif
            onComplete(image, new ImageResult(extent));
        }