Example #1
0
        /// <summary>
        /// The save button_ on click.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        private void SaveButton_OnClick(object sender, RoutedEventArgs e)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.Filter = "picture (*.png)|*.png|jpg (*.jpg)|*.jpg";
            Files bild = new Files();
            bildDataDataContext context = new bildDataDataContext();

            if (saveFileDialog.ShowDialog() == true)
            {
                Rect   bounds = VisualTreeHelper.GetDescendantBounds(this.Canvas);
                double dpi    = 96d;


                RenderTargetBitmap rtb = new RenderTargetBitmap(
                    (int)bounds.Width,
                    (int)bounds.Height,
                    dpi,
                    dpi,
                    PixelFormats.Default);


                DrawingVisual dv = new DrawingVisual();
                using (DrawingContext dc = dv.RenderOpen())
                {
                    VisualBrush vb = new VisualBrush(this.Canvas);
                    dc.DrawRectangle(vb, null, new Rect(new Point(), bounds.Size));
                }

                rtb.Render(dv);
                BitmapEncoder pngEncoder = new PngBitmapEncoder();
                pngEncoder.Frames.Add(BitmapFrame.Create(rtb));

                try
                {
                    MemoryStream ms = new System.IO.MemoryStream();

                    pngEncoder.Save(ms);
                    ms.Close();

                    File.WriteAllBytes(saveFileDialog.FileName, ms.ToArray());
                    Binary bildData = ms.ToArray();
                    bild.Image = bildData;
                    bild.Id    = context.Files.ToArray().Last().Id + 1;
                    context.Files.InsertOnSubmit(bild);
                    context.SubmitChanges();
                }
                catch (Exception err)
                {
                    MessageBox.Show(err.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }
Example #2
0
        /// <summary>
        /// The button base_ on click.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
        {
            bildDataDataContext context = new bildDataDataContext();

            Console.WriteLine("vorher");

            var query = from b in context.Files select b;

            foreach (var v in query)
            {
                Console.WriteLine(v);
            }
            Console.WriteLine("nachher");
        }
Example #3
0
        /// <summary>
        /// The load button_ on click.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        private void LoadButton_OnClick(object sender, RoutedEventArgs e)
        {
            ImageBrush brush = new ImageBrush();

            bildDataDataContext context = new bildDataDataContext();
            MemoryStream        ms      = new MemoryStream(context.Files.ToArray().Last().Image.ToArray());

            BitmapImage gemalde = new BitmapImage();

            ms.Position = 0;
            gemalde.BeginInit();
            gemalde.StreamSource = ms;
            gemalde.CacheOption  = BitmapCacheOption.OnLoad;
            gemalde.EndInit();
            brush.ImageSource      = gemalde;
            this.Canvas.Background = brush;
        }