コード例 #1
0
        private void GridScreenshot()
        {
            try
            {
                var width  = (int)MainGrid.ActualWidth + 10;
                var height = (int)MainGrid.ActualHeight + 10;

                var renderBitmap = new RenderTargetBitmap(width, height, 96d, 96d, PixelFormats.Pbgra32);
                MainGrid.Measure(new Size(width, height));
                MainGrid.Arrange(new Rect(new Size(width, height)));

                renderBitmap.Render(MainGrid);

                var pngImage = new PngBitmapEncoder();
                pngImage.Frames.Add(BitmapFrame.Create(renderBitmap));
                using (var fileStream = File.Create($@"C:\Users\LPI\Desktop\souk_again\yo\{DateTime.Now.ToString("yyyyMMddhhmmss")}.jpg"))
                {
                    pngImage.Save(fileStream);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error while screenshoting : " + ex.Message);
            }
        }
コード例 #2
0
        private void PlateImage_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            double width  = MainGrid.ColumnDefinitions[1].ActualWidth;
            double height = MainGrid.RowDefinitions[1].ActualHeight;

            Size size = new Size();

            MainGrid.Measure(size);

            m_xPixelRange = (int)width;
            m_yPixelRange = (int)height;

            ColumnButtonGrid.Width = m_xPixelRange;
            RowButtonGrid.Height   = m_yPixelRange;

            m_plateBitmap     = BitmapFactory.New((int)m_xPixelRange, (int)m_yPixelRange);
            PlateImage.Source = m_plateBitmap;

            m_selectBitmap     = BitmapFactory.New((int)m_xPixelRange, (int)m_yPixelRange);
            SelectImage.Source = m_selectBitmap;

            m_extraRow.Height   = new GridLength((double)(m_yPixelRange % m_rows));
            m_extraColumn.Width = new GridLength((double)(m_xPixelRange % m_cols));

            DrawPlate();
        }
コード例 #3
0
ファイル: MainWindow.xaml.cs プロジェクト: uyle/PhotoCollager
        private void SaveToFile()
        {
            int height = (int)MainGrid.Height;
            int width  = (int)MainGrid.Width;

            //BitmapSource bmp = CreateBitmapFromVisual(width, height, MainGrid, true);
            Size size = MainGrid.RenderSize;

            RenderTargetBitmap bmp = new RenderTargetBitmap(width, height, 96, 96, PixelFormats.Pbgra32);

            MainGrid.Measure(size);
            MainGrid.Arrange(new Rect(size));
            bmp.Render(MainGrid);

            string file      = "test.png"; // this.txtFilename.Text;
            string Extension = System.IO.Path.GetExtension(file).ToLower();

            BitmapEncoder encoder;

            if (Extension == ".gif")
            {
                encoder = new GifBitmapEncoder();
            }
            else if (Extension == ".png")
            {
                encoder = new PngBitmapEncoder();
            }
            else if (Extension == ".jpg")
            {
                encoder = new JpegBitmapEncoder();
            }
            else
            {
                return;
            }
            encoder.Frames.Add(BitmapFrame.Create(bmp));
            using (Stream stm = File.Create(file))
            {
                encoder.Save(stm);
            }
        }
コード例 #4
0
        protected override void OnSizeAllocated(double width, double height)
        {
            base.OnSizeAllocated(width, height);

            if (width < 10)
            {
                return;
            }

            MainGrid.Padding           = new Thickness(0);
            MainListView.ItemWidth     = (int)((width * 0.90) / 3d);
            MainListView.ItemHeight    = (int)(MainListView.ItemWidth * 1.40d);
            MainListView.WidthRequest  = width * 0.90; //90% of the width.
            MainListView.HeightRequest = (MainListView.ItemHeight + MainListView.ItemSpacing) * 2;

            var req  = MainListView.Measure(double.PositiveInfinity, double.PositiveInfinity);
            var req2 = MainGrid.Measure(double.PositiveInfinity, double.NegativeInfinity);

            var widthAvailable  = width - req2.Request.Width;
            var heightAvailable = height - req2.Request.Height - PhotosLabel.Height - PhotosLabel.Margin.VerticalThickness;

            MainGrid.Padding = new Thickness(widthAvailable / 2d, heightAvailable / 2d, widthAvailable / 2d, heightAvailable / 2d);
        }