Esempio n. 1
0
        private InkStrokeContainer GetCurrentStrokesView(DateTimeOffset time)
        {
            var inkStrokeContainer = new InkStrokeContainer();

            // The purpose of this sample is to demonstrate the timestamp usage,
            // not the algorithm. (The time complexity of the code is O(N^2).)
            foreach (var stroke in strokesToReplay)
            {
                var s = GetPartialStroke(stroke, time);
                if (s != null)
                {
                    inkStrokeContainer.AddStroke(s);
                }
            }

            return(inkStrokeContainer);
        }
        private async Task SaveStrokesToBitmap(WriteableBitmap b)
        {
            Rect imgRect = new Rect(0, 0, b.PixelWidth, b.PixelHeight);
            InkStrokeContainer container = TheInkCanvas.InkPresenter.StrokeContainer;
            InkStrokeBuilder   builder   = new InkStrokeBuilder();

            // Unsichtbare Tinte!
            InkDrawingAttributes da = TheInkCanvas.InkPresenter.CopyDefaultDrawingAttributes();

            da.Size = new Size(0.1, 0.1);
            builder.SetDefaultDrawingAttributes(da);

            // Strich in oberer linker Ecke einfügen
            InkStroke topLeft = builder.CreateStroke(new List <Point>()
            {
                new Point(1, 1),
                new Point(2, 2)
            });

            container.AddStroke(topLeft);

            // Strich in unterer Rechter Ecke einfügen
            InkStroke bottomRight = builder.CreateStroke(new List <Point>()
            {
                new Point(imgRect.Width - 2, imgRect.Height - 2),
                new Point(imgRect.Width - 1, imgRect.Height - 1)
            });

            container.AddStroke(bottomRight);

            // Striche in WriteableBitmap speichern
            WriteableBitmap bmp;

            using (InMemoryRandomAccessStream ims =
                       new InMemoryRandomAccessStream())
            {
                await container.SaveAsync(ims);

                bmp = await new WriteableBitmap(1, 1)
                      .FromStream(ims, BitmapPixelFormat.Bgra8);
            }
            // Bilder zusammenfügen
            b.Blit(imgRect, bmp, imgRect, WriteableBitmapExtensions.BlendMode.Alpha);
        }
Esempio n. 3
0
        private async Task loadContentAsync()
        {
            if (_pdfDocument != null)
            {
                ContentBitmaps.Clear();
                PageIndex = default(uint);
                PageCount = _pdfDocument.PageCount;
                var overlays = await LoadOverlayAsync();

                for (uint idx = 0; idx < PageCount; idx++)
                {
                    using (var page = _pdfDocument.GetPage(idx))
                    {
                        var bitmapImage = new BitmapImage();
                        using (var bmpStream = new InMemoryRandomAccessStream())
                        {
                            await page.RenderToStreamAsync(bmpStream);

                            await bitmapImage.SetSourceAsync(bmpStream);
                        }

                        var inkStrokes = new InkStrokeContainer();
                        if (overlays.ContainsKey(idx))
                        {
                            using (var inkStream = new InMemoryRandomAccessStream())
                            {
                                await inkStream.WriteAsync(overlays[idx].AsBuffer());

                                await inkStrokes.LoadAsync(inkStream.GetInputStreamAt(0));
                            }
                        }

                        ContentBitmaps.Add(
                            new SimpleFlipPage
                        {
                            Index      = idx,
                            Image      = bitmapImage,
                            InkStrokes = inkStrokes
                        }
                            );
                    }
                }
            }
        }
Esempio n. 4
0
 public void AddStrokes(int pageNumber, InkStrokeContainer inkStrokeContainer, IReadOnlyList <InkStroke> inkStrokes)
 {
     if (!inkStrokesDict.ContainsKey(pageNumber))
     {
         inkStrokesDict[pageNumber] = new List <InkStroke>(inkStrokes);
     }
     else
     {
         List <InkStroke> strokesInPage = inkStrokesDict[pageNumber];
         foreach (InkStroke stroke in inkStrokes)
         {
             if (!strokesInPage.Contains(stroke))
             {
                 strokesInPage.Add(stroke);
                 inkStrokesDict[pageNumber] = strokesInPage;
             }
         }
     }
     SaveInking(pageNumber);
 }
Esempio n. 5
0
        public bool EraseStrokes(int pageNumber, InkStrokeContainer inkStrokeContainer, IReadOnlyList <InkStroke> inkStrokes)
        {
            bool             strokeRemoved      = false;
            bool             inkingChanged      = false;
            List <InkStroke> strokesToBeRemoved = new List <InkStroke>();

            if (inkStrokesDict.TryGetValue(pageNumber, out List <InkStroke> inAppStrokes))
            {
                foreach (InkStroke inkStroke in inkStrokes)
                {
                    strokeRemoved = inAppStrokes.Remove(inkStroke);
                    if (!strokeRemoved)
                    {
                        strokesToBeRemoved.Add(inkStroke);
                    }
                    else
                    {
                        inkingChanged = true;
                    }
                }
                if (inkingChanged)
                {
                    SaveInking(pageNumber);
                }
            }
            else
            {
                strokesToBeRemoved.AddRange(inkStrokes);
            }
            if (strokesToBeRemoved.Count > 0)
            {
                if (!erasedStrokesDict.TryGetValue(pageNumber, out List <InkStroke> erasedStrokes))
                {
                    erasedStrokes = new List <InkStroke>();
                }
                erasedStrokes.AddRange(strokesToBeRemoved);
                erasedStrokesDict[pageNumber] = erasedStrokes;
                SaveInking(-pageNumber);
            }
            return(strokeRemoved);
        }
Esempio n. 6
0
        public async Task SetInkData_NewInkStrokeContainer_UpdatesInkCanvas()
        {
            InkStrokeContainer expectedStrokeContainer = null;
            InkStrokeContainer actualStrokeContainer   = null;
            List <InkCanvas>   canvases = new List <InkCanvas>();
            await UIService.FindAllAsync(canvases);

            await UIService.RunOnUI(() => {
                expectedStrokeContainer = new InkStrokeContainer();
            });

            var mockInkData = new Mock <IInkData>();

            mockInkData.Setup(x => x.StrokeContainer).Returns(expectedStrokeContainer);

            await UIService.RunOnUI(() => {
                MockCanvasViewModel.Instance.InkData = mockInkData.Object;
                actualStrokeContainer = canvases[0].InkPresenter.StrokeContainer;
            });

            Assert.AreSame(expectedStrokeContainer, actualStrokeContainer);
        }
Esempio n. 7
0
        private void InkPresenter_StrokesCollected(InkPresenter sender, InkStrokesCollectedEventArgs args)
        {
            // Custom drying
            var strokes = _inkSynchronizer.BeginDry();

            var container     = new InkStrokeContainer();
            var clonedStrokes = from item in strokes select item.Clone();

            container.AddStrokes(clonedStrokes);
            viewModel.AddStroke(container);

            _inkSynchronizer.EndDry();
            drawingCanvas.Invalidate();

            if (inkToShapeButton.IsChecked.Value) // Store a copy of the strokes for recognition if button is checked
            {
                viewModel.RecognizeStrokes(clonedStrokes);
            }
            else
            {
                viewModel.StopRecognizingStrokes();
            }
        }
Esempio n. 8
0
        public async void ReadXml(XmlReader reader)
        {
            reader.Read();
            Title       = reader.ReadElementContentAsString("Title", "");
            Description = reader.ReadElementContentAsString("Description", "");
            string s = reader.ReadElementContentAsString("Status", "");

            Status = (JobStatus)Enum.Parse(typeof(JobStatus), s);

            InMemoryRandomAccessStream ms = new InMemoryRandomAccessStream();
            DataWriter dw = new DataWriter(ms.GetOutputStreamAt(0));

            byte[] tempBytes = new byte[1024];
            int    bytesRead = 0;

            do
            {
                bytesRead = reader.ReadElementContentAsBinHex(tempBytes, 0, 1024);
                if (bytesRead > 0)
                {
                    dw.WriteBytes(tempBytes);
                }
            } while (bytesRead == 1024);

            await dw.StoreAsync();

            if (ms.Size > 0)
            {
                InkStrokeContainer inkCont = new InkStrokeContainer();
                await inkCont.LoadAsync(ms);

                Strokes = inkCont.GetStrokes().ToList();
            }

            reader.Skip();
        }
        /// <summary>
        /// Load the family and their notes from local storage
        /// </summary>
        /// <returns>Null if there was no model to load, otherwise, the deserialized model</returns>
        private async Task <Model> LoadModelAsync()
        {
            Model model = null;

            InkStrokeContainer combinedStrokes     = new InkStrokeContainer(); // To avoid managing individual files for every InkCanvas, we will combine all ink stroke information into one container
            List <int>         InkStrokesPerCanvas = new List <int>();

            try
            {
                StorageFile modelDataFile = await ApplicationData.Current.LocalFolder.GetFileAsync(NOTES_MODEL_FILE);

                using (IRandomAccessStream randomAccessStream = await modelDataFile.OpenAsync(FileAccessMode.ReadWrite))
                {
                    // Load the model which contains the people and the note collection
                    try
                    {
                        DataContractJsonSerializer modelSerializer = new DataContractJsonSerializer(typeof(Model));
                        model = (Model)modelSerializer.ReadObject(randomAccessStream.AsStream());
                    }
                    catch (System.Runtime.Serialization.SerializationException)
                    {
                        System.Diagnostics.Debug.Assert(false, "Failed to load serialized model");
                        return(null);
                    }
                }

                // For each sticky note, load the number of inkstrokes it contains
                StorageFile inkDataFile = await ApplicationData.Current.LocalFolder.GetFileAsync(NOTES_INK_FILE);

                using (IInputStream inkStream = await inkDataFile.OpenSequentialReadAsync())
                {
                    bool       combinedStrokesExist = false;
                    DataReader reader = new DataReader(inkStream);
                    foreach (StickyNote n in model.StickyNotes)
                    {
                        await reader.LoadAsync(sizeof(int)); // You need to buffer the data before you can read from a DataReader.

                        int numberOfInkStrokes = reader.ReadInt32();
                        InkStrokesPerCanvas.Add(numberOfInkStrokes);
                        combinedStrokesExist |= numberOfInkStrokes > 0;
                    }

                    // Load the ink data
                    if (combinedStrokesExist)
                    {
                        await combinedStrokes.LoadAsync(inkStream);
                    }
                } // using inkStream
            }     // try
            catch (FileNotFoundException)
            {
                // No data to load. We'll start with a fresh model
                return(null);
            }

            // Factor out the inkstrokes from the big container into each note
            int allStrokesIndex = 0, noteIndex = 0;
            IReadOnlyList <InkStroke> allStrokes = combinedStrokes.GetStrokes();

            foreach (StickyNote n in model.StickyNotes)
            {
                // InkStrokeContainers can't be serialized using the default xml/json serialization.
                // So create a new one and fill it up from the data we restored
                n.Ink = new InkStrokeContainer();
                // pull out the ink strokes that belong to this note
                for (int i = 0; i < InkStrokesPerCanvas[noteIndex]; i++)
                {
                    n.Ink.AddStroke(allStrokes[allStrokesIndex++].Clone());
                }
                ++noteIndex;
            }

            return(model);
        }
Esempio n. 10
0
 // updates the canvas portion of the groups content
 public void updateCanvasFrom(GroupsContent gc)
 {
     strokes        = gc.strokes;
     backgroundPath = gc.backgroundPath;
     imageContainer = gc.imageContainer;
 }
        private void OnInkToolbarAction(object sender, RoutedEventArgs e)
        {
            string option = (sender as Button).Name;

            switch (option)
            {
            case "Copy":
            case "Cut":
                this.copyContainer = new InkStrokeContainer();
                if (this.renderedStrokes.Any())
                {
                    foreach (InkStroke stroke in this.renderedStrokes.Where(s => s.Selected))
                    {
                        this.copyContainer.AddStroke(stroke.Clone());
                    }

                    this.copyContainer.SelectWithPolyLine(this.lasso.Points);
                    this.copyContainer.CopySelectedToClipboard();
                    if (option == "Cut")
                    {
                        this.OnEraserClicked(sender, null);
                    }

                    this.canvas.Invalidate();
                }
                break;

            case "Paste":
                //Unselects all previously selected areas
                foreach (InkStrokeContainer container in this.strokes)
                {
                    container.SelectWithLine(new Point(0, 0), new Point(0, 0));
                }

                //Fake paste to determine pasted content size
                InkStrokeContainer pasteFakeContainer = new InkStrokeContainer();
                Rect pastedContentArea = pasteFakeContainer.PasteFromClipboard(this.toolbarPosition);

                //Paste it ensuring it fits client size
                InkStrokeContainer pasteContainer = new InkStrokeContainer();
                Point pastePoint         = this.EnsureFit(this.toolbarPosition, pastedContentArea);
                Rect  pastedBoundingRect = pasteContainer.PasteFromClipboard(pastePoint);
                this.DrawBoundingRect(pastedBoundingRect);

                //Selects pasted ink
                List <Point> pastedLasso = new List <Point>();
                pastedLasso.Add(new Point(pastedBoundingRect.X, pastedBoundingRect.Y));
                pastedLasso.Add(new Point(pastedBoundingRect.X + pastedBoundingRect.Width, pastedBoundingRect.Y));
                pastedLasso.Add(new Point(pastedBoundingRect.X + pastedBoundingRect.Width, pastedBoundingRect.Y + pastedBoundingRect.Height));
                pastedLasso.Add(new Point(pastedBoundingRect.X, pastedBoundingRect.Y + pastedBoundingRect.Height));
                pastedLasso.Add(new Point(pastedBoundingRect.X, pastedBoundingRect.Y));
                pasteContainer.SelectWithPolyLine(pastedLasso);
                this.strokes.Add(pasteContainer);
                this.canvas.Invalidate();
                //Se lasso matching pasted content
                this.lasso = new Polyline()
                {
                    Stroke          = new SolidColorBrush(Colors.Blue),
                    StrokeThickness = 1,
                    StrokeDashArray = new DoubleCollection()
                    {
                        5, 2
                    },
                };
                foreach (Point lassoPoint in pastedLasso)
                {
                    this.lasso.Points.Add(lassoPoint);
                }
                //We move into lasso mode to let user move pasted selection
                //this.OnLassoChecked(this,null);
                this.hasPasted = true;
                break;

            case "Delete":
                this.OnEraserClicked(sender, null);
                break;
            }

            this.InkSelectionToolbar.Visibility = Visibility.Collapsed;
        }
        private void UnprocessedInput_PointerMoved(InkUnprocessedInput sender, PointerEventArgs args)
        {
            switch (this.toolbarMode)
            {
            case ToolbarMode.Erasing:
                if (!this.isErasing)
                {
                    return;
                }
                //bool invalidate = false;

                //draw rectange for eraser
                eraser = new Rect(args.CurrentPoint.Position, new Size(30, 30));

                #region try 2
                InkStroke          newStroke1    = null;
                InkStroke          newStroke2    = null;
                List <InkPoint>    newpoints1    = new List <InkPoint>();
                List <InkPoint>    newpoints2    = new List <InkPoint>();
                InkStrokeContainer newContainer1 = new InkStrokeContainer();
                InkStrokeContainer newContainer2 = new InkStrokeContainer();

                InkStrokeBuilder          creator = new InkStrokeBuilder();
                System.Numerics.Matrix3x2 matr    = System.Numerics.Matrix3x2.Identity;

                foreach (InkStrokeContainer item in this.strokes.ToArray())
                {
                    Rect rect = item.SelectWithLine(this.lastPoint, args.CurrentPoint.Position);
                    if (rect.Width == 0 && rect.Height == 0)
                    {
                        Debug.WriteLine("skipping InkStrokeContainer  from strokes collection");
                        continue;
                    }

                    Debug.WriteLine("ciclyng strokes collection");
                    //Rect rect = item.SelectWithLine(this.lastPoint, args.CurrentPoint.Position);
                    //if (rect.IsEmpty) continue;
                    //if (rect.Width * rect.Height > 0)
                    //{


                    var selectedStrokes = item.GetStrokes();

                    foreach (InkStroke stroke in selectedStrokes)
                    {
                        if (stroke.Selected == false)
                        {
                            continue;
                        }

                        //Debug.WriteLine("ciclyng selectedStrokes");

                        creator.SetDefaultDrawingAttributes(stroke.DrawingAttributes);
                        bool switchToSecond = false;

                        foreach (InkPoint point in stroke.GetInkPoints())
                        {
                            //Debug.WriteLine("ciclyng GetInkPoints");

                            if (eraser.Contains(point.Position) == false)
                            {
                                if (switchToSecond == false)
                                {
                                    newpoints1.Add(point);
                                }
                                else
                                {
                                    newpoints2.Add(point);
                                }
                            }
                            else
                            {
                                switchToSecond = true;
                            }
                        }

                        if (newpoints1.Count > 0)
                        {
                            newStroke1 = creator.CreateStrokeFromInkPoints(newpoints1, matr);

                            if (newStroke1 != null)
                            {
                                if (newContainer1 == null)
                                {
                                    newContainer1 = new InkStrokeContainer();
                                }
                                newContainer1.AddStroke(newStroke1);
                            }
                        }

                        if (newpoints2.Count > 0)
                        {
                            newStroke2 = creator.CreateStrokeFromInkPoints(newpoints2, matr);
                            if (newStroke2 != null)
                            {
                                if (newContainer2 == null)
                                {
                                    newContainer2 = new InkStrokeContainer();
                                }
                                newContainer2.AddStroke(newStroke2);
                            }
                        }
                    }

                    this.strokes.Remove(item);


                    if (newContainer1 != null)
                    {
                        this.strokes.Add(newContainer1);
                    }
                    if (newContainer2 != null)
                    {
                        this.strokes.Add(newContainer2);
                    }
                    //canvas.Invalidate();
                    //invalidate = true;

                    //}
                }


                newStroke1 = null;
                newStroke2 = null;
                newpoints1.Clear();
                newpoints2.Clear();
                newContainer1 = new InkStrokeContainer();
                newContainer2 = new InkStrokeContainer();
                #endregion

                this.lastPoint = args.CurrentPoint.Position;
                args.Handled   = true;
                //if (invalidate)
                //{
                //	this.canvas.Invalidate();
                //}
                //eraser = Rect.Empty;
                canvas.Invalidate();
                break;

            case ToolbarMode.Lasso:
                if (this.isBoundRect)
                {
                    if (args.CurrentPoint.RawPosition.X > 0 && args.CurrentPoint.RawPosition.Y > 0 && args.CurrentPoint.RawPosition.X < this.ActualWidth && args.CurrentPoint.RawPosition.Y < this.ActualHeight)
                    {
                        this.lasso.Points.Add(args.CurrentPoint.RawPosition);
                    }
                }
                if (this.isSelectionDragging)
                {
                    Rect  boundingRect = Rect.Empty;
                    Point upperLeft    = new Point(args.CurrentPoint.RawPosition.X - this.selectionOffset.Width, args.CurrentPoint.RawPosition.Y - this.selectionOffset.Height);
                    if (upperLeft.X > 0 && upperLeft.Y > 0 && upperLeft.X + this.selectionRectangle.Value.Width < this.ActualWidth && upperLeft.Y + this.selectionRectangle.Value.Height < this.ActualHeight)
                    {
                        Point point = new Point(args.CurrentPoint.RawPosition.X - this.selectionDragPoint.X, args.CurrentPoint.RawPosition.Y - this.selectionDragPoint.Y);
                        foreach (InkStrokeContainer item in this.strokes.ToArray())
                        {
                            Rect rect = item.MoveSelected(point);
                            if (rect.Width > 0 && rect.Height > 0)
                            {
                                boundingRect = RectHelper.Union(boundingRect, rect);
                            }
                        }

                        this.DrawBoundingRect(boundingRect);
                    }

                    this.canvas.Invalidate();
                    this.selectionDragPoint = args.CurrentPoint.RawPosition;
                }
                break;
            }
        }
 public void save(InkStrokeContainer strokeContainer)
 {
     this.createCSV(strokeContainer.GetStrokes());
     this.saveGIF(strokeContainer);
 }
Esempio n. 14
0
 internal void AddStroke(InkStrokeContainer container)
 {
     _strokes.Add(container);
 }
Esempio n. 15
0
 public void EraseStrokes(int pageNumber, InkStrokeContainer inkStrokeContainer, IReadOnlyList <InkStroke> inkStrokes)
 {
     inAppInking.EraseStrokes(pageNumber, inkStrokeContainer, inkStrokes);
     inkDictionary[pageNumber] = inkStrokeContainer;
 }
Esempio n. 16
0
        public async Task <MainCanvasParams> OpenProject(List <InkStrokeContainer> currentStrokes, StorageFolder currentFolder, ProjectMetaData metaData, List <CanvasComponent> components)
        {
            List <InkStrokeContainer> newStrokes     = new List <InkStrokeContainer>();
            TemplateChoice            templateChoice = TemplateChoice.None;
            //Let the user pick a project folder to open
            FolderPicker folderPicker = new FolderPicker();

            folderPicker.FileTypeFilter.Add("*");

            StorageFolder newFolder = await folderPicker.PickSingleFolderAsync();

            if (newFolder != null)
            {
                IReadOnlyList <StorageFile> files = await newFolder.GetFilesAsync();

                foreach (var f in files)
                {
                    if (f.Name.Equals("metadata.txt"))
                    {
                        string text = await FileIO.ReadTextAsync(f);

                        templateChoice = (TemplateChoice)Enum.Parse(typeof(TemplateChoice), text);
                    }
                    else if (f.Name.Equals("components.txt"))
                    {
                        // read file load shapes
                        string text = await FileIO.ReadTextAsync(f);

                        string[] xmlComponents = text.Split('\n');

                        foreach (string component in xmlComponents)
                        {
                            if (component.Length > 0)
                            {
                                components.Add(Serializer.Deserialize <CanvasComponent>(component));
                            }
                        }
                    }
                    else if (f != null && f.FileType.Equals(".gif"))
                    {
                        // Open a file stream for reading.
                        IRandomAccessStream stream = await f.OpenAsync(FileAccessMode.Read);

                        // Read from file.
                        using (var inputStream = stream.GetInputStreamAt(0))
                        {
                            var container = new InkStrokeContainer();
                            await container.LoadAsync(inputStream);

                            //Add the strokes stored in the files
                            newStrokes.Add(container);
                        }
                        stream.Dispose();
                    }
                }
                var result = await ConfirmSave(currentStrokes, currentFolder, metaData, components);

                if (result != ContentDialogResult.None)
                {
                    return(new MainCanvasParams(newStrokes, newFolder, templateChoice, components));
                }
            }
            return(null);
        }
Esempio n. 17
0
 public static void SetInkStrokes(DependencyObject obj, InkStrokeContainer value) =>
 obj.SetValue(InkStrokesProperty, value);
Esempio n. 18
0
        public InkStrokeContainer returnSig()
        {
            InkStrokeContainer currentStrokes = inkCanvas.InkPresenter.StrokeContainer;

            return(currentStrokes);
        }
Esempio n. 19
0
            public void InsertInUnDoRedoForEraseStroke(List <InkStrokeContainer> strokes, InkStrokeContainer container, CanvasControl drawingCanvas)
            {
                ICommand cmd = new EraseStrokeCommand(strokes, container, drawingCanvas);

                _Undocommands.Push(cmd);
                _Redocommands.Clear();
            }
Esempio n. 20
0
 public EraseStrokeCommand(List <InkStrokeContainer> strokes, InkStrokeContainer container, CanvasControl drawingCanvas)
 {
     _Strokes       = strokes;
     _Container     = container;
     _DrawingCanvas = drawingCanvas;
 }
Esempio n. 21
0
        public async void WriteXml(XmlWriter writer)
        {
            writer.WriteElementString("Title", Title);
            writer.WriteElementString("Description", Description);
            writer.WriteElementString("Status", Status.ToString());
            writer.WriteStartElement("Stokes");
            if (Strokes != null && Strokes.Count > 0)
            {
                using (InMemoryRandomAccessStream ms = new InMemoryRandomAccessStream())
                {
                    InkStrokeContainer inkCont = new InkStrokeContainer();

                    foreach (InkStroke stroke in Strokes)
                    {
                        inkCont.AddStroke(stroke.Clone());
                    }

                    await inkCont.SaveAsync(ms);

                    await ms.FlushAsync();

                    byte[] bytes = new byte[ms.Size];
                    //var dataWriter = new DataWriter(ms);
                    var reader = new DataReader(ms.GetInputStreamAt(0));
                    await reader.LoadAsync((uint)ms.Size);

                    reader.ReadBytes(bytes);

                    writer.WriteBinHex(bytes, 0, (int)ms.Size);
                }
            }
            else
            {
                byte[] bytes = new byte[1];
                bytes[0] = 0xF;
                writer.WriteBinHex(bytes, 0, 1);
            }
            writer.WriteEndElement();

            writer.WriteStartElement("Photo");

            if (Photo != null)
            {
                InMemoryRandomAccessStream ms = new InMemoryRandomAccessStream();
                if (null != ms)
                {
                    try
                    {
                        byte[] buffer = new byte[4 * Photo.PixelWidth * Photo.PixelHeight];
                        Photo.CopyToBuffer(buffer.AsBuffer());

                        writer.WriteBinHex(buffer, 0, (int)buffer.Length);
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.Message);
                    }
                }
            }
            else

            {
                byte[] bytes = new byte[1];
                bytes[0] = 0;
                writer.WriteBinHex(bytes, 0, 1);
            }
            writer.WriteEndElement();
        }
Esempio n. 22
0
        /// <summary>
        /// Captures the ink from an <see cref="InkCanvas"/> control.
        /// </summary>
        /// <param name="strokeContainer">
        /// The <see cref="InkStrokeContainer"/> containing the strokes to be rendered.
        /// </param>
        /// <param name="rootRenderElement">
        /// A <see cref="FrameworkElement"/> which wraps the canvas.
        /// </param>
        /// <param name="targetFile">
        /// A <see cref="StorageFile"/> to store the image in.
        /// </param>
        /// <param name="encoderId">
        /// A <see cref="BitmapEncoder"/> ID to use to render the image.
        /// </param>
        /// <returns>
        /// Returns the <see cref="StorageFile"/> containing the rendered ink.
        /// </returns>
        public static async Task <StorageFile> CaptureInkToFileAsync(
            this InkStrokeContainer strokeContainer,
            FrameworkElement rootRenderElement,
            StorageFile targetFile,
            Guid encoderId)
        {
            if (targetFile != null)
            {
                var renderBitmap = new RenderTargetBitmap();
                await renderBitmap.RenderAsync(rootRenderElement);

                var bitmapSizeAt96Dpi = new Size(renderBitmap.PixelWidth, renderBitmap.PixelHeight);

                var pixels = await renderBitmap.GetPixelsAsync();

                var win2DDevice = CanvasDevice.GetSharedDevice();

                using (
                    var target = new CanvasRenderTarget(
                        win2DDevice,
                        (float)rootRenderElement.ActualWidth,
                        (float)rootRenderElement.ActualHeight,
                        96.0f))
                {
                    using (var drawingSession = target.CreateDrawingSession())
                    {
                        using (
                            var canvasBitmap = CanvasBitmap.CreateFromBytes(
                                win2DDevice,
                                pixels,
                                (int)bitmapSizeAt96Dpi.Width,
                                (int)bitmapSizeAt96Dpi.Height,
                                DirectXPixelFormat.B8G8R8A8UIntNormalized,
                                96.0f))
                        {
                            drawingSession.DrawImage(
                                canvasBitmap,
                                new Rect(0, 0, target.SizeInPixels.Width, target.SizeInPixels.Height),
                                new Rect(0, 0, bitmapSizeAt96Dpi.Width, bitmapSizeAt96Dpi.Height));
                        }
                        drawingSession.Units = CanvasUnits.Pixels;
                        drawingSession.DrawInk(strokeContainer.GetStrokes());
                    }

                    using (var stream = await targetFile.OpenAsync(FileAccessMode.ReadWrite))
                    {
                        var displayInfo = DisplayInformation.GetForCurrentView();
                        var encoder     = await BitmapEncoder.CreateAsync(encoderId, stream);

                        encoder.SetPixelData(
                            BitmapPixelFormat.Bgra8,
                            BitmapAlphaMode.Ignore,
                            target.SizeInPixels.Width,
                            target.SizeInPixels.Height,
                            displayInfo.RawDpiX,
                            displayInfo.RawDpiY,
                            target.GetPixelBytes());

                        await encoder.FlushAsync();
                    }
                }
            }

            return(targetFile);
        }
Esempio n. 23
0
        public async void ReadXml(XmlReader reader)
        {
            reader.Read();
            Title       = reader.ReadElementContentAsString("Title", "");
            Description = reader.ReadElementContentAsString("Description", "");
            string s = reader.ReadElementContentAsString("Status", "");

            Status = (JobStatus)Enum.Parse(typeof(JobStatus), s);

            if (!reader.IsEmptyElement)
            {
                InMemoryRandomAccessStream ms = new InMemoryRandomAccessStream();
                DataWriter dw = new DataWriter(ms.GetOutputStreamAt(0));
                byte[]     tempBytes;
                int        bytesRead  = 0;
                int        totalBytes = 0;
                do
                {
                    tempBytes = new byte[1024];
                    bytesRead = reader.ReadElementContentAsBinHex(tempBytes, 0, 1024);
                    if (bytesRead > 0)
                    {
                        dw.WriteBytes(tempBytes);
                        totalBytes += bytesRead;
                    }
                } while (bytesRead == 1024);

                await dw.StoreAsync();

                if (totalBytes > 1)
                {
                    InkStrokeContainer inkCont = new InkStrokeContainer();
                    await inkCont.LoadAsync(ms);

                    Strokes = inkCont.GetStrokes().ToList();
                }
                reader.ReadEndElement();
            }
            else
            {
                reader.Read();
            }

            if (!reader.IsEmptyElement)
            {
                InMemoryRandomAccessStream ms = new InMemoryRandomAccessStream();
                DataWriter dw = new DataWriter(ms.GetOutputStreamAt(0));
                byte[]     tempBytes;
                int        bytesRead      = 0;
                int        totalBytesRead = 0;
                do
                {
                    tempBytes = new byte[1024];
                    bytesRead = reader.ReadContentAsBinHex(tempBytes, 0, 1024);
                    if (bytesRead > 0)
                    {
                        dw.WriteBytes(tempBytes);
                        totalBytesRead += bytesRead;
                    }
                } while (bytesRead == 1024);

                await dw.StoreAsync();

                if (totalBytesRead > 1)
                {
                    //load bytes as image
                    byte[] bytes = new byte[ms.Size];
                    //var dataWriter = new DataWriter(ms);
                    var dataReader = new DataReader(ms.GetInputStreamAt(0));

                    await dataReader.LoadAsync((uint)ms.Size);

                    dataReader.ReadBytes(bytes);
                    //TODO: this should change based on the resolution you store the photos at
                    Photo = new SoftwareBitmap(BitmapPixelFormat.Bgra8, 640, 360);
                    Photo.CopyFromBuffer(bytes.AsBuffer());
                }
                reader.ReadEndElement();
            }
            else
            {
                reader.Read();
            }


            reader.Skip();
        }
Esempio n. 24
0
 public InkStrokesService(InkStrokeContainer _strokeContainer)
 {
     strokeContainer = _strokeContainer;
 }