Пример #1
0
        public async Task<ReturnElements> GetScreen()
        {
            ReturnElements retelement = new ReturnElements();

            // Get the bitmap and display it.
            var dataPackageView = Windows.ApplicationModel.DataTransfer.Clipboard.GetContent();
            if (dataPackageView.Contains(StandardDataFormats.Bitmap))
            {
                IRandomAccessStreamReference imageReceived = null;
                try
                {
                    imageReceived = await dataPackageView.GetBitmapAsync();

                    if (imageReceived != null)
                    {
                        using (IRandomAccessStream imageStream = await imageReceived.OpenReadAsync())
                        {
                            StorageFolder folder = await ApplicationData.Current.LocalFolder.GetFolderAsync("Temp");
                            if (folder == null)
                                folder = await ApplicationData.Current.LocalFolder.CreateFolderAsync("Temp", CreationCollisionOption.ReplaceExisting);

                            StorageFile file = await folder.CreateFileAsync("MyPainter.png", CreationCollisionOption.ReplaceExisting);
                            Windows.Storage.Streams.Buffer buffer = new Windows.Storage.Streams.Buffer((uint)imageStream.Size);
                            await imageStream.ReadAsync(buffer, (uint)imageStream.Size, InputStreamOptions.None);
                            await FileIO.WriteBufferAsync(file, buffer);
                            control.factory.IsGetScreenSucccess = true;
                            retelement.success = true;
                            return retelement;
                        }
                    }
                }
                catch (Exception ex)
                {
                    control.factory.IsGetScreenSucccess = false;
                    retelement.success = false;
                    return retelement;
                }

            }
            control.factory.IsGetScreenSucccess = false;
            retelement.success = false;
            return retelement;
        }
Пример #2
0
        public async Task<ReturnElements> takePhoto(double width, double height)
        {
            try
            {
                dialog = new CameraCaptureUI();
                Size aspectRatio = new Size(width, height);
                dialog.PhotoSettings.CroppedAspectRatio = aspectRatio;
                dialog.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Png;

                StorageFile file = await dialog.CaptureFileAsync(CameraCaptureUIMode.Photo);


                    using (IRandomAccessStream fileStream = await file.OpenAsync(FileAccessMode.Read))
                    {
                        ReturnElements ReElements = new ReturnElements();
                        ReElements.bitmapImage.SetSource(fileStream);
                        StorageFolder folder = null;
                        bool Failed = false;
                        try
                        {
                            folder = await ApplicationData.Current.LocalFolder.GetFolderAsync("Picture");
                        }
                        catch (System.Exception ex)
                        {
                            Failed = true;
                        }
                        if (Failed || folder == null)
                            folder = await ApplicationData.Current.LocalFolder.CreateFolderAsync("Picture");
                        await file.MoveAsync(folder);
                        ReElements.filename = file.Name;
                        return ReElements;

                }
            }
            catch (System.Exception ex)
            {
                ReturnElements appEle = new ReturnElements();
                appEle.bitmapImage = null;
                appEle.filename = "cannot find";
                return appEle;
            }
        }