Example #1
0
        internal void AddBodyFrame(DrawingImage drawingImage)
        {
            if (this.isRecording)
            {
                //DateTime now = DateTime.Now;
                //TimeSpan timeSpan = this.StartDate.Subtract(now);
                //string path = this.GetBodyFramePath() + now.GetStringTime() + ".png";
                //RenderTargetBitmap bitmap = drawingImage.ToBitmap();
                //frames.Add(new Frame(bitmap.Clone(), path, timeSpan, Frame.FrameType.Body));
                ////bitmap.ToImageFile(path);

                _Frame   frame;
                TimeSpan timeWithPreviousFrame;

                DateTime now      = DateTime.Now;
                TimeSpan timeSpan = now.Subtract(this.StartDate);

                string path = this.GetColorFramePath() + now.GetStringTime() + ".png";
                if (this.previousFrame == null)
                {
                    timeWithPreviousFrame = timeSpan;
                }
                else
                {
                    timeWithPreviousFrame = timeSpan.Subtract(this.previousFrame.Time);
                }

                RenderTargetBitmap bitmap = drawingImage.ToBitmap();
                frame = new _Frame(bitmap.Clone(), path, timeSpan, timeWithPreviousFrame, _Frame.FrameType.Body);
                this.previousFrame = frame;
                frames.Add(frame);

                //bitmap.ToImageFile(path);
            }
        }
Example #2
0
        public BitmapSource EndDraw()
        {
            // Flush the content to be drawn
            this.context.Close();

            // Render the bitmap
            this.bitmap.Render(this.visual);

            BitmapSource cloned = bitmap.Clone();

            cloned.Freeze();

            return(cloned);
        }
Example #3
0
 private void TakeASnapshot()
 {
     this.Dispatcher.Invoke(new Action(() =>
     {
         try
         {
             sv_MainCanvas.UpdateLayout();
             drawingCanvas.UpdateLayout();
             canvasesContainer.UpdateLayout();
             double dpi = 96;
             //prepare to render the notes
             RenderTargetBitmap noteContainerRenderTargetBitmap = new RenderTargetBitmap((int)canvasesContainer.ActualWidth, (int)canvasesContainer.ActualHeight, dpi, dpi, PixelFormats.Pbgra32);
             noteContainerRenderTargetBitmap.Render(canvasesContainer);
             ImageSource NoteContainerImgSrc          = (ImageSource)noteContainerRenderTargetBitmap.Clone();
             BitmapFrame resizedNoteContainerBmpFrame = Utilities.UtilitiesLib.CreateResizedBitmapFrame(NoteContainerImgSrc, (int)(canvasesContainer.ActualWidth * 3 / 4), (int)(canvasesContainer.Height * 3 / 4), 0);
             PngBitmapEncoder imageEncoder            = new PngBitmapEncoder();
             imageEncoder.Frames.Add(BitmapFrame.Create(resizedNoteContainerBmpFrame));
             //imageEncoder.Frames.Add(BitmapFrame.Create(renderTargetBitmap));
             byte[] screenshotBytes = new byte[1];
             using (MemoryStream stream = new MemoryStream())
             {
                 imageEncoder.Save(stream);
                 stream.Seek(0, 0);
                 screenshotBytes = stream.ToArray();
                 Utilities.GlobalObjects.currentScreenshotBytes = screenshotBytes;
                 //broadcastScreenshot(screenshotBytes);
                 Task.Factory.StartNew(() =>
                 {
                     BoardScreenUpdater.GetInstance(dropboxGeneralNoteDownloader.Storage).UpdateMetaplanBoardScreen(new MemoryStream(screenshotBytes));
                 });
                 //bgUploader.RunWorkerAsync(new MemoryStream(screenshotBytes));
             }
         }
         catch (Exception ex)
         {
             Utilities.UtilitiesLib.LogError(ex);
         }
     }));
 }
Example #4
0
        public void PaintAnimation(LocalDecoder decoder)
        {
            try
            {
                frameCount   = decoder.Frames.Count;
                framePos     = 0;
                bitmapFrames = decoder.Frames;
                bmp          = decoder.Frames[0];

                int width     = (int)Image.MinWidth;
                int height    = (int)Image.MinHeight;
                int imgWidth  = bmp.PixelWidth;
                int imgHeight = bmp.PixelHeight;

                ObjectAnimationUsingKeyFrames animation = new ObjectAnimationUsingKeyFrames();

                isAnimation = true;

                long time = 0;
                long span = 1000 * 10;


                GetScaleValue v = GetScale(imgWidth, imgHeight, width, height, bmp.DpiX, bmp.DpiY);
                scaleX = v.scaleX;
                scaleY = v.scaleY;
                int resizeWidth  = v.resizeWidth;
                int resizeHeight = v.resizeHight;

                RenderTargetBitmap rbmp = new RenderTargetBitmap(imgWidth, imgHeight, bmp.DpiX, bmp.DpiY, PixelFormats.Pbgra32);

                for (int i = 0; i < frameCount; i++)
                {
                    BitmapSource   fbmp = bitmapFrames[i];
                    BitmapMetadata metadata = fbmp.Metadata as BitmapMetadata;
                    int            delay = 33, startX = 0, startY = 0, w = imgWidth, h = imgHeight;

                    if (decoder.Delays != null)
                    {
                        delay = decoder.Delays[i];
                    }

                    DrawingVisual  drawingVisual  = new DrawingVisual();
                    DrawingContext drawingContext = drawingVisual.RenderOpen();
                    drawingContext.DrawImage(fbmp, new Rect(startX, startY, w, h));
                    drawingContext.Close();
                    rbmp.Render(drawingVisual);

                    BitmapSource wbmp = rbmp.Clone();

                    DiscreteObjectKeyFrame key = new DiscreteObjectKeyFrame();
                    key.KeyTime = new TimeSpan(time);
                    key.Value   = wbmp;
                    animation.KeyFrames.Add(key);
                    time += delay * span;
                }
                animation.RepeatBehavior = RepeatBehavior.Forever;
                animation.Duration       = new TimeSpan(time);

                offsetX = (width - resizeWidth) / 2.0;
                offsetY = (height - resizeHeight) / 2.0;

                TransformGroup transforms = new TransformGroup();
                transforms.Children.Add(new ScaleTransform(scaleX, scaleY));
                Matrix matrix = new Matrix(1, 0, 0, 1, offsetX, offsetY);
                transforms.Children.Add(new MatrixTransform(matrix));
                Image.RenderTransform = transforms;

                Image.Source = bmp;
                Image.BeginAnimation(Image.SourceProperty, animation);
            }
            catch (Exception e)
            {
                LogWriter.write(e.ToString());
            }
        }
        // イメージを初期状態にリセット

        private void resetImage()
        {
            Bitmap = (RenderTargetBitmap)_original.Clone();
        }
        /// <summary>
        /// Image export method
        /// Encodes a RenderTargetBitmap as a graphic-file (bmp, gif, jpeg, png or tiff) and saves it with the given filename.
        /// </summary>
        /// <param name="filename">Filename</param>
        /// <returns>bool if the export was successfully</returns>
        /// <author>Thomas Meents, Bernhard Bruns, Andrej Albrecht</author>
        public bool export(String filename)
        {
            try
            {
                processModelCanvas.Background = Brushes.White;
                RenderTargetBitmap render = new RenderTargetBitmap((int)processModelCanvas.Width, (int)processModelCanvas.Height, 96d, 96d, PixelFormats.Pbgra32);
                render.Clone();
                processModelCanvas.Measure(new Size((int)processModelCanvas.Width, (int)processModelCanvas.Height));
                processModelCanvas.Arrange(new Rect(new Size((int)processModelCanvas.Width, (int)processModelCanvas.Height)));

                render.Render(processModelCanvas);

                switch (this.filetype)
                {
                case ".bmp":
                    BmpBitmapEncoder bmpEncoder = new BmpBitmapEncoder();
                    bmpEncoder.Frames.Add(BitmapFrame.Create(render));
                    using (FileStream bmpFile = File.Create(filename))
                    {
                        bmpEncoder.Save(bmpFile);
                    }
                    break;

                case ".gif":
                    GifBitmapEncoder gifEncoder = new GifBitmapEncoder();
                    gifEncoder.Frames.Add(BitmapFrame.Create(render));
                    using (FileStream gifFile = File.Create(filename))
                    {
                        gifEncoder.Save(gifFile);
                    }
                    break;

                case ".jpeg":
                    JpegBitmapEncoder jpegEncoder = new JpegBitmapEncoder();
                    jpegEncoder.Frames.Add(BitmapFrame.Create(render));
                    using (FileStream jpegFile = File.Create(filename))
                    {
                        jpegEncoder.Save(jpegFile);
                    }
                    break;

                case ".png":
                    PngBitmapEncoder pngEncoder = new PngBitmapEncoder();
                    pngEncoder.Frames.Add(BitmapFrame.Create(render));
                    using (FileStream pngFile = File.Create(filename))
                    {
                        pngEncoder.Save(pngFile);
                    }
                    break;

                case ".tiff":
                    TiffBitmapEncoder tiffEncoder = new TiffBitmapEncoder();
                    tiffEncoder.Frames.Add(BitmapFrame.Create(render));
                    using (FileStream tiffFile = File.Create(filename))
                    {
                        tiffEncoder.Save(tiffFile);
                    }
                    break;
                }

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }