Esempio n. 1
0
        /// <summary>
        /// Gets a render of the current UIElement
        /// </summary>
        /// <param name="source">UIElement to screenshot</param>
        /// <param name="dpi">The DPI of the source.</param>
        /// <param name="size">The size of the destination image.</param>
        /// <returns>An ImageSource</returns>
        public static RenderTargetBitmap GetRender(this Grid source, double dpi, System.Windows.Size?size = null)
        {
            var bounds = VisualTreeHelper.GetDescendantBounds(source);

            var scale  = Math.Round(dpi / 96d, 2);
            var width  = size?.Width ?? (bounds.Width + bounds.X) * scale;
            var height = size?.Height ?? (bounds.Height + bounds.Y) * scale;

            var rtb = new RenderTargetBitmap((int)Math.Round(width), (int)Math.Round(height), dpi, dpi, PixelFormats.Pbgra32);

            var dv = new DrawingVisual();

            using (var ctx = dv.RenderOpen())
            {
                var vb = new VisualBrush(source);

                var locationRect = new System.Windows.Point(bounds.X, bounds.Y);
                var sizeRect     = new System.Windows.Size(bounds.Width, bounds.Height);

                ctx.DrawRectangle(vb, null, new Rect(locationRect, sizeRect));
            }

            rtb.Render(dv);
            return((RenderTargetBitmap)rtb.GetAsFrozen());
        }
Esempio n. 2
0
        private void Export(string filter, bool useXaml, System.Windows.Size?size = null)
        {
            var saveFileDialog = new SaveFileDialog
            {
                Filter           = filter,
                InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
            };

            if (saveFileDialog.ShowDialog() == true)
            {
                var surface = ParentSurface as SciChartSurface;
                if (surface == null)
                {
                    return;
                }

                var exportType = filter.ToUpper().Contains("XPS") ? ExportType.Xps : ExportType.Png;

                if (size.HasValue)
                {
                    surface.ExportToFile(saveFileDialog.FileName, exportType, useXaml, size.Value);
                }
                else
                {
                    surface.ExportToFile(saveFileDialog.FileName, exportType, useXaml);
                }

                Process.Start(saveFileDialog.FileName);
            }
        }
Esempio n. 3
0
        public static Bitmap Resize(string path, System.Windows.Size?size = null)
        {
            var m_size = size ?? new System.Windows.Size((double)480, (double)360);

            var bitmap = Bitmap.FromFile(path) as Bitmap;

            return(Resize(bitmap, m_size));
        }
Esempio n. 4
0
        public void Show(System.Windows.Size?defaultSize)
        {
            if (innerCanvas != null)
            {
                innerCanvas.DefaultSize = defaultSize;
            }

            Show();
            Focus();
        }
		protected override System.Windows.Size MeasureOverride(System.Windows.Size availableSize)
		{
			if (Element?.MeasureOverrideDelegate == null)
				return base.MeasureOverride(availableSize);

			// The user has specified a different implementation of MeasureOverride
			System.Windows.Size? result = Element.MeasureOverrideDelegate(this, availableSize);

			// If the delegate returns a Size, we use it; 
			// if it returns null, fall back to the default implementation
			return result ?? base.MeasureOverride(availableSize);
		}
		protected override System.Windows.Size ArrangeOverride(System.Windows.Size finalSize)
		{
			if (Element?.ArrangeOverrideDelegate == null)
				return base.ArrangeOverride(finalSize);

			// The user has specified a different implementation of ArrangeOverride
			System.Windows.Size? result = Element.ArrangeOverrideDelegate(this, finalSize);

			// If the delegate returns a Size, we use it; 
			// if it returns null, fall back to the default implementation
			return result ?? base.ArrangeOverride(finalSize);
		}
Esempio n. 7
0
 void Control_SizeChanged(object sender, sw.SizeChangedEventArgs e)
 {
     if (previousRenderSize == Control.RenderSize)
     {
         return;
     }
     // update parents only when the render size has changed
     previousRenderSize = Control.RenderSize;
     if (Wrap != WrapMode.None)
     {
         UpdatePreferredSize();
     }
 }
Esempio n. 8
0
        public void Show(int timeOutSecond, System.Windows.Size?defaultSize)
        {
            if (timeOutSecond > 0)
            {
                if (timeOutTimmer == null)
                {
                    timeOutTimmer       = new Timer();
                    timeOutTimmer.Tick += OnTimeOutTimmerTick;
                }
                timeOutTimmer.Interval = timeOutSecond * 1000;
                timeOutTimmer.Start();
            }

            if (innerCanvas != null)
            {
                innerCanvas.DefaultSize = defaultSize;
            }

            Show();
            Focus();
        }
Esempio n. 9
0
        public static Bitmap Resize(Bitmap p_bitmap, System.Windows.Size?size = null)
        {
            var m_size = size ?? new System.Windows.Size((double)480, (double)360);

            using (Bitmap m_bitmap = new Bitmap((int)m_size.Width, (int)m_size.Height))
            {
                using (Graphics graphics = Graphics.FromImage(m_bitmap))
                {
                    graphics.Clear(Color.FromArgb(-1));

                    if ((float)p_bitmap.Width / (float)m_size.Width == (float)p_bitmap.Height / (float)m_size.Height)     //Target size has a 1:1 aspect ratio
                    {
                        graphics.DrawImage(p_bitmap, 0, 0, (int)m_size.Width, (int)m_size.Height);
                    }

                    else if ((float)p_bitmap.Width / (float)m_size.Width > (float)p_bitmap.Height / (float)m_size.Height)     //There will be white space on the top and bottom
                    {
                        graphics.DrawImage(p_bitmap, 0f, (float)m_bitmap.Height / 2f - (p_bitmap.Height * ((float)m_bitmap.Width / (float)p_bitmap.Width)) / 2f, (float)m_bitmap.Width, p_bitmap.Height * ((float)m_bitmap.Width / (float)p_bitmap.Width));
                    }

                    else if ((float)p_bitmap.Width / (float)m_size.Width < (float)p_bitmap.Height / (float)m_size.Height)     //There will be white space on the sides
                    {
                        graphics.DrawImage(p_bitmap, (float)m_bitmap.Width / 2f - (p_bitmap.Width * ((float)m_bitmap.Height / (float)p_bitmap.Height)) / 2f, 0f, p_bitmap.Width * ((float)m_bitmap.Height / (float)p_bitmap.Height), (float)m_bitmap.Height);
                    }

                    graphics.Save();

                    using (MemoryStream stream = new MemoryStream())
                    {
                        m_bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
                        var bitmap = new Bitmap(stream);
                        stream.Close();

                        return(bitmap);
                    }
                }
            }
        }
Esempio n. 10
0
        void Control_SizeChanged(object sender, sw.SizeChangedEventArgs e)
        {
            if (previousRenderSize == null)
            {
                // don't update preferred sizes when called the first time.
                // when there's many labels this causes a major slowdown
                // the initial size should already have been taken care of by
                // the initial layout pass.
                previousRenderSize = Control.RenderSize;
                return;
            }

            if (previousRenderSize == Control.RenderSize)
            {
                return;
            }
            // update parents only when the render size has changed
            previousRenderSize = Control.RenderSize;
            if (Wrap != WrapMode.None)
            {
                UpdatePreferredSize();
            }
        }
Esempio n. 11
0
        private void OnScreenCaputred(object sender, ScreenShot2Lib.ScreenCaputredEventArgs e)
        {
            //set last size
            lastSize = new System.Windows.Size(e.Bmp.Width, e.Bmp.Height);


            Show();

            //test
            var bmp = e.Bmp;
            //var win = new Img { SizeToContent = SizeToContent.WidthAndHeight, ResizeMode = ResizeMode.NoResize };
            Img win = new Img {
                SizeToContent = SizeToContent.WidthAndHeight, ResizeMode = ResizeMode.NoResize
            };
            var canvas = new Canvas {
                Width = bmp.Width, Height = bmp.Height, Background = new ImageBrush(bmp)
            };

            win.Content = canvas;

            win.Show();
            //
            //string file="pic01";
            //ImageSave(canvas,file);

            var cdlg = new Microsoft.Win32.SaveFileDialog();

            cdlg.Filter = "*.jpg;*.bmp|*.jpg;*.bmp|*.png|*.png";

            cdlg.Title            = "保存";
            cdlg.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
            if (cdlg.ShowDialog(this) == true)
            {
                System.Windows.MessageBox.Show(cdlg.FileName);
            }
            SaveToImage(canvas, cdlg.FileName);
        }
Esempio n. 12
0
        /// <summary>
        /// Gets a render of the current UIElement
        /// </summary>
        /// <param name="source">UIElement to screenshot</param>
        /// <param name="dpi">The DPI of the source.</param>
        /// <param name="size">The size of the destination image.</param>
        /// <returns>An ImageSource</returns>
        public static RenderTargetBitmap GetRender(this UIElement source, double dpi, System.Windows.Size?size = null)
        {
            var bounds = VisualTreeHelper.GetDescendantBounds(source);

            var scale  = Math.Round(dpi / 96d, 2);
            var width  = (bounds.Width + bounds.X) * scale;
            var height = (bounds.Height + bounds.Y) * scale;

            #region If no bounds

            if (bounds.IsEmpty)
            {
                var control = source as Control;

                if (control != null)
                {
                    width  = control.ActualWidth * scale;
                    height = control.ActualHeight * scale;
                }

                bounds = new Rect(new System.Windows.Point(0d, 0d), new System.Windows.Point(width, height));
            }

            #endregion

            var rtb = new RenderTargetBitmap((int)Math.Round(width), (int)Math.Round(height), dpi, dpi, PixelFormats.Pbgra32);

            var dv = new DrawingVisual();
            using (var ctx = dv.RenderOpen())
            {
                var vb = new VisualBrush(source);

                var locationRect = new System.Windows.Point(bounds.X, bounds.Y);
                var sizeRect     = new System.Windows.Size(bounds.Width, bounds.Height);

                ctx.DrawRectangle(vb, null, new Rect(locationRect, sizeRect));
            }

            rtb.Render(dv);
            return((RenderTargetBitmap)rtb.GetAsFrozen());
        }
Esempio n. 13
0
        private void OnScreenCaputred(object sender, ScreenShot2Lib.ScreenCaputredEventArgs e)
        {
            //set last size
            lastSize = new System.Windows.Size(e.Bmp.Width, e.Bmp.Height);


            Show();

            //test
            var bmp = e.Bmp;
            //var win = new Img { SizeToContent = SizeToContent.WidthAndHeight, ResizeMode = ResizeMode.NoResize };
            Img win = new Img { SizeToContent = SizeToContent.WidthAndHeight, ResizeMode = ResizeMode.NoResize };
            var canvas = new Canvas { Width = bmp.Width, Height = bmp.Height, Background = new ImageBrush(bmp) };

            win.Content = canvas;
   
            win.Show();
            //
            //string file="pic01";
            //ImageSave(canvas,file);

            var cdlg = new Microsoft.Win32.SaveFileDialog();
            cdlg.Filter = "*.jpg;*.bmp|*.jpg;*.bmp|*.png|*.png";
            
            cdlg.Title = "保存";
            cdlg.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
            if (cdlg.ShowDialog(this) == true)
            {
                System.Windows.MessageBox.Show(cdlg.FileName);

            }
            SaveToImage(canvas,cdlg.FileName);
        }