Esempio n. 1
0
        public static async System.Threading.Tasks.Task <byte[]> ReadBytesFromFileAsync(string fileName)
        {
            try
            {
                Windows.Storage.StorageFolder tempFolder = await Windows.Storage.StorageFolder.GetFolderFromPathAsync(Options.options.tempFolderPath);

                Windows.Storage.StorageFile file = await tempFolder.GetFileAsyncServiceAsync(text, apiArgs);

                // TODO: obsolete to use DataReader? use await Windows.Storage.FileIO.Read...(file);
                using (Windows.Storage.Streams.IRandomAccessStream stream = await file.OpenReadAsync())
                {
                    using (Windows.Storage.Streams.DataReader reader = new Windows.Storage.Streams.DataReader(stream.GetInputStreamAt(0)))
                    {
                        await reader.LoadAsync((uint)stream.Size);

                        byte[] bytes = new byte[stream.Size];
                        reader.ReadBytes(bytes);
                        return(bytes);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.WriteLine(ex.Message);
                return(null);
            }
        }
        private async void FileMenuOpen_Click(object sender, RoutedEventArgs e)
        {
            var picker = new Windows.Storage.Pickers.FileOpenPicker();

            picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.List;
            picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary;
            picker.FileTypeFilter.Add(".cpp");
            picker.FileTypeFilter.Add(".c");
            picker.FileTypeFilter.Add(".cc");
            picker.FileTypeFilter.Add(".cxx");
            picker.FileTypeFilter.Add(".c++");
            picker.FileTypeFilter.Add(".cp");

            Windows.Storage.StorageFile file = await picker.PickSingleFileAsync();

            if (file != null)
            {
                using (var inputStream = await file.OpenReadAsync())
                    using (var classicStream = inputStream.AsStreamForRead())
                        using (var streamReader = new StreamReader(classicStream))
                        {
                            CodeInput.Text = streamReader.ReadToEnd();
                        }
            }
        }
        private async void Img_Empleado_DoubleTapped(object sender, DoubleTappedRoutedEventArgs e)
        {
            var memoryStream = new MemoryStream();

            var picker = new Windows.Storage.Pickers.FileOpenPicker();

            picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;
            picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;
            picker.FileTypeFilter.Add(".jpg");
            picker.FileTypeFilter.Add(".jpeg");
            picker.FileTypeFilter.Add(".png");

            Windows.Storage.StorageFile file = await picker.PickSingleFileAsync();

            if (file != null)
            {
                var bitmap = new BitmapImage();
                using (var stream = await file.OpenReadAsync())
                {
                    await bitmap.SetSourceAsync(stream);

                    Stream stream2 = await file.OpenStreamForReadAsync();

                    stream2.CopyTo(memoryStream);
                    Empleado_Actual.Photo = memoryStream.ToArray();
                }

                Img_Empleado.Source = bitmap;

                // Empleado_Actual.Photo = await ImageToBytes (bitmap);
            }
        }
Esempio n. 4
0
        public static async Task <string> GetDataAsString(String folder, String file)
        {
            Windows.Storage.StorageFolder storageFolder = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync(folder);

            Windows.Storage.StorageFile storageFile = await storageFolder.GetFileAsync(file);

            string contents = "";

            try
            {
                using (IRandomAccessStream textStream = await storageFile.OpenReadAsync())
                {
                    using (DataReader textReader = new DataReader(textStream))
                    {
                        uint textLength = (uint)textStream.Size;
                        await textReader.LoadAsync(textLength);

                        contents = textReader.ReadString(textLength);
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("GetDataAsString : " + ex);
            }
            return(contents);
        }
Esempio n. 5
0
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            progressRing.IsActive = true;
            //
            var picker = new Windows.Storage.Pickers.FileOpenPicker();

            picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;
            picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;
            picker.FileTypeFilter.Add(".jpg");
            picker.FileTypeFilter.Add(".jpeg");
            picker.FileTypeFilter.Add(".png");
            picker.FileTypeFilter.Add(".bmp");
            Windows.Storage.StorageFile file = await picker.PickSingleFileAsync();

            if (file != null)
            {
                using (var stream = await file.OpenReadAsync())
                {
                    _bitmap = new BitmapImage();
                    await _bitmap.SetSourceAsync(stream);

                    Image1.Source = _bitmap;
                    //
                    BitmapDecoder bitmapDecoder = await BitmapDecoder.CreateAsync(stream);

                    //
                    var pixels = await bitmapDecoder.GetPixelDataAsync();

                    //----------------------------------------------------------


                    MainFunction main = new MainFunction();

                    main.MsgReporter = this;// optional

                    var resultPixels = await main.Run(pixels.DetachPixelData(), (int)bitmapDecoder.PixelWidth, (int)bitmapDecoder.PixelHeight);

                    //
                    using (var ms = new InMemoryRandomAccessStream())
                    {
                        float devicedpi = Windows.Graphics.Display.DisplayInformation.GetForCurrentView().LogicalDpi;
                        var   encoder   = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, ms);

                        encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Ignore, bitmapDecoder.PixelWidth, bitmapDecoder.PixelHeight, devicedpi, devicedpi, resultPixels);
                        await encoder.FlushAsync();

                        var _bitmap2 = new BitmapImage();
                        await _bitmap2.SetSourceAsync(ms);

                        Image2.Source = _bitmap2;
                    }


                    //--
                }
            }
            //
            progressRing.IsActive = false;
        }
Esempio n. 6
0
        protected async static Task <Windows.Storage.Streams.IRandomAccessStreamWithContentType> GetFileReaderStreamAsync(Windows.Storage.StorageFile fle)
        {
            Windows.Storage.Streams.IRandomAccessStreamWithContentType strm = null;

            strm = await fle.OpenReadAsync();

            return(strm);
        }
        public async Task PlayDeniedSound()
        {
            Windows.Storage.StorageFolder folder = await Windows.ApplicationModel.Package
                                                   .Current.InstalledLocation.GetFolderAsync("Assets");

            Windows.Storage.StorageFile file = await folder.GetFileAsync("denied.mp3");

            var stream = await file.OpenReadAsync();

            _sound.SetSource(stream, file.ContentType);
            _sound.Play();
        }
        public async Task PlaySound()
        {
            MediaElement mysong = new MediaElement();

            Windows.Storage.StorageFolder folder = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync("Assets");

            Windows.Storage.StorageFile file = await folder.GetFileAsync("not-bad.mp3");

            var stream = await file.OpenReadAsync();

            mysong.SetSource(stream, file.ContentType);
            mysong.Play();
        }
Esempio n. 9
0
        public static async Task ChangeBackground(string localUri, string folder)
        {
            //if (_state.IsSharpDxRendering)
            //{
            //    var br = RenderingService.BackgroundRenderer;
            //    br.ChangeBackground(localUri, folder);
            //}
            //else
            //{
            string path;

            Windows.Storage.StorageFile storageFile = null;
            if (folder == string.Empty)
            {
                path        = Windows.ApplicationModel.Package.Current.InstalledLocation.Path;
                storageFile = await Windows.Storage.StorageFile.GetFileFromPathAsync(path + localUri);
            }
            else if (folder == "PicturesLibrary")
            {
                var localUriParts = localUri.Split("\\".ToCharArray());

                var foundFolder = await Windows.Storage.KnownFolders.PicturesLibrary.GetFolderAsync(localUriParts[0]);

                storageFile = await foundFolder.GetFileAsync(localUriParts[1]);
            }
            else if (folder == "PublicPicturesLibrary")
            {
                var localUriParts = localUri.Split("\\".ToCharArray());

                var foundFolder = await Windows.Storage.KnownFolders.PicturesLibrary.GetFolderAsync(localUriParts[0]);

                storageFile = await foundFolder.GetFileAsync(localUriParts[1]);
            }

            if (storageFile != null)
            {
                using (var ms = await storageFile.OpenReadAsync())
                {
                    BackgroundBitmapImage.SetSource(ms);
                    //await BackgroundBitmapImage.SetSourceAsync(ms);  //<== FAILS TO UPDATE IMAGE ON SURFACE RT (GENERATION 1) ,
                    //    doesn't throw an error (appears successful)
                }
            }


            //}
        }
Esempio n. 10
0
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            //Clear searchbox
            ViewAQuotes.Blocks.Clear();

            Paragraph deskQuoteObjects   = new Paragraph();
            Run       deskQuoteObjectRun = new Run();

            Windows.Storage.StorageFolder storageFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
            Windows.Storage.StorageFile   file          = await storageFolder.GetFileAsync("quotes.json");

            using (var inputStream = await file.OpenReadAsync())
                using (var classicStream = inputStream.AsStreamForRead())
                    using (var streamReader = new StreamReader(classicStream))
                    {
                        while (streamReader.Peek() >= 0)
                        {
                            string    json       = streamReader.ReadLine();
                            DeskQuote printQuote = JsonConvert.DeserializeObject <DeskQuote>(json);


                            if (variableMaterial.SelectedItem.ToString() == System.Convert.ToString(printQuote.newDesk1.surface))
                            {
                                //Desk.SurfaceMaterials MaterialSelected = (Desk.SurfaceMaterials)Enum.Parse(typeof(Desk.SurfaceMaterials), MaterialSelectedText);
                                //Print the matching quotes

                                deskQuoteObjectRun.Text +=
                                    "Date: \t" + printQuote.date +
                                    "\n First Name: \t" + printQuote.FirstName +
                                    "\n Last Name: \t" + printQuote.LastName +
                                    "\n Desk Specs:" +
                                    "\n Width: \t\t" + System.Convert.ToString(printQuote.newDesk1.width) +
                                    "\n Depth: \t\t" + System.Convert.ToString(printQuote.newDesk1.depth) +
                                    "\n Drawers: \t" + System.Convert.ToString(printQuote.newDesk1.drawerCount) +
                                    "\n Material: \t\t" + System.Convert.ToString(printQuote.newDesk1.surface) +
                                    "\n Shipping: \t" + System.Convert.ToString(printQuote.ShippingDays) + " Day" +
                                    "\n Total Cost: \t" + "$" + System.Convert.ToString(printQuote.DeskCost + printQuote.ShippingCost) +
                                    "\n" +
                                    "==============================" +
                                    "\n";
                            }
                        }
                        deskQuoteObjects.Inlines.Add(deskQuoteObjectRun);
                        ViewAQuotes.Blocks.Add(deskQuoteObjects);
                    }
        }
Esempio n. 11
0
        public static async Task <IRandomAccessStream> GetDataAsStream(String folder, String file)
        {
            Windows.Storage.StorageFolder storageFolder = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync(folder);

            Windows.Storage.StorageFile storageFile = await storageFolder.GetFileAsync(file);

            IRandomAccessStream contents = null;

            try
            {
                contents = await storageFile.OpenReadAsync();
            }
            catch (Exception ex)
            {
                Debug.WriteLine("GetDataAsString : " + ex);
            }
            return(contents);
        }
Esempio n. 12
0
        /*
         * private void time_chng(object sender, TimePickerValueChangedEventArgs e){
         *  TimeSpan tm = ((TimePicker)sender).Time;
         *  // Set up the notification text.
         *  XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);
         *  XmlNodeList strings = toastXml.GetElementsByTagName("text");
         *  StackPanel parent_stck = (StackPanel)((TimePicker)sender).Parent;
         *  ListView parent_lv = (ListView)parent_stck.Parent;
         *  TextBox tb_title = (TextBox)parent_lv.Items.ElementAt(0);
         *  String texto = tb_title.Text;
         *  strings[0].AppendChild(toastXml.CreateTextNode(texto));
         *  strings[1].AppendChild(toastXml.CreateTextNode("Fecha: " + tm));
         *  /*DateTimeOffset dt = new Windows.Globalization.Calendar().GetDateTime();
         *    dt += tm;*
         *  // Create the toast notification object.
         *  //ScheduledToastNotification toast = new ScheduledToastNotification(toastXml, dt);
         *  try{
         *      ScheduledToastNotification toast = new ScheduledToastNotification(toastXml, new Windows.Globalization.Calendar().GetDateTime(), tm, 5);
         *      // Add to the schedule.
         *      toast.Id = "h" + new Random().Next();
         *      ToastNotificationManager.CreateToastNotifier().AddToSchedule(toast);
         *  }catch(Exception excep){
         *  }
         * }
         *
         * private void fecha_chng(object sender, DatePickerValueChangedEventArgs e){
         *  DateTimeOffset selD = ((DatePicker)sender).Date;
         *
         *  // Set up the notification text.
         *  XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);
         *  XmlNodeList strings = toastXml.GetElementsByTagName("text");
         *  StackPanel parent_stck = (StackPanel)((DatePicker)sender).Parent;
         *  ListView parent_lv = (ListView)parent_stck.Parent;
         *  TextBox tb_title = (TextBox)parent_lv.Items.ElementAt(0);
         *  String texto = tb_title.Text;
         *  strings[0].AppendChild(toastXml.CreateTextNode(texto));
         *  strings[1].AppendChild(toastXml.CreateTextNode("Fecha: " + selD));
         *
         *  // Create the toast notification object.
         *  selD=selD.AddSeconds(30);
         *  try{
         *      ScheduledToastNotification toast = new ScheduledToastNotification(toastXml, selD);
         *      toast.Id = "h" + new Random().Next();
         *      // Add to the schedule.
         *      ToastNotificationManager.CreateToastNotifier().AddToSchedule(toast);
         *  }catch(Exception excep){
         *  }
         * }
         */

        private async void selimg(object sender, RoutedEventArgs e)
        {
            Windows.Storage.Pickers.FileOpenPicker f = new Windows.Storage.Pickers.FileOpenPicker();
            f.FileTypeFilter.Add(".jpg");
            f.FileTypeFilter.Add(".jpeg");
            f.FileTypeFilter.Add(".png");
            Windows.Storage.StorageFile file = await f.PickSingleFileAsync();

            if (file != null)
            {
                var stream = await file.OpenReadAsync();

                BitmapImage bitmapImage = new BitmapImage();
                bitmapImage.SetSource(stream);
                ImageBrush ib = new ImageBrush();
                ib.ImageSource = bitmapImage;
                ((ListView)((StackPanel)((Button)sender).Parent).Parent).Background = ib;
            }
        }
Esempio n. 13
0
        private async void CargarImagen_Click(object sender, RoutedEventArgs e)
        {
            var picker = new Windows.Storage.Pickers.FileOpenPicker();

            picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;
            picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;
            picker.FileTypeFilter.Add(".jpg");
            picker.FileTypeFilter.Add(".jpeg");
            picker.FileTypeFilter.Add(".png");

            Windows.Storage.StorageFile file = await picker.PickSingleFileAsync();

            var bitmap = new BitmapImage();

            using (var stream = await file.OpenReadAsync())
            {
                await bitmap.SetSourceAsync(stream);
            }
            Imagen_Mostrada.Source = bitmap;
        }
Esempio n. 14
0
        private async void AddButton_Click(object sender, RoutedEventArgs e)
        {
            var picker = new Windows.Storage.Pickers.FileOpenPicker();

            picker.FileTypeFilter.Add("*");

            Windows.Storage.StorageFile file = await picker.PickSingleFileAsync();

            if (file != null)
            {
                StatusText.Text       = $"Uploading {file.Name}...";
                StatusArea.Visibility = Visibility.Visible;

                using (var stream = await file.OpenReadAsync())
                {
                    var url = GetUploadUrl(Config.UploadFile);
                    await this.UploadFile(url, stream, file.Name);
                }
            }
        }
Esempio n. 15
0
        /*
         * Ez a függvény kezeli le azt az eseményt amikor a "open file" gombra kattintunk.
         * Megnyit egy file explorert és a kiválaszott fájlt beolvassa bytearraybe, amit pedig át is alakítunk bitmapimaggé.
         * A byte arrayt átadjuk a detect függvénynek, a képet és a detektált arcokat pedig a kiíró függvénynek.
         */
        public async void openfileButton(object sender, RoutedEventArgs e)
        {
            var picker = new Windows.Storage.Pickers.FileOpenPicker();

            picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;
            picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;
            picker.FileTypeFilter.Add(".jpg");
            picker.FileTypeFilter.Add(".jpeg");
            picker.FileTypeFilter.Add(".png");
            Windows.Storage.StorageFile file = await picker.PickSingleFileAsync();

            if (file == null)
            {
                return;
            }

            byte[] imagearray = null;

            using (var stream = await file.OpenReadAsync())
            {
                imagearray = new byte[stream.Size];
                using (var reader = new DataReader(stream))
                {
                    await reader.LoadAsync((uint)stream.Size);

                    reader.ReadBytes(imagearray);
                }
            }
            BitmapImage image = new BitmapImage();

            using (InMemoryRandomAccessStream stream = new InMemoryRandomAccessStream())
            {
                await stream.WriteAsync(imagearray.AsBuffer());

                stream.Seek(0);
                await image.SetSourceAsync(stream);
            }

            FaceDetectResponse[] faces = Detect(imagearray);
            displayFaces(faces, image);
        }
Esempio n. 16
0
        public async Task <IRandomAccessStreamWithContentType> pickAPicture()
        {
            var picker = new Windows.Storage.Pickers.FileOpenPicker();

            picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;
            picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;
            picker.FileTypeFilter.Add(".jpg");
            picker.FileTypeFilter.Add(".jpeg");
            picker.FileTypeFilter.Add(".png");

            Windows.Storage.StorageFile file = await picker.PickSingleFileAsync();

            if (file != null)
            {
                return(await file.OpenReadAsync());
            }
            else
            {
                return(null);
            }
        }
Esempio n. 17
0
        public async static Task <string> ConvertStorageFileToBase64(Windows.Storage.StorageFile file)
        {
            byte[] fileBytes = null;
            if (file == null)
            {
                return(null);
            }
            using (var stream = await file.OpenReadAsync())
            {
                fileBytes = new byte[stream.Size];
                using (var reader = new DataReader(stream))
                {
                    await reader.LoadAsync((uint)stream.Size);

                    reader.ReadBytes(fileBytes);
                }
            }
            string base64 = Convert.ToBase64String(fileBytes);

            return(base64);
        }
Esempio n. 18
0
        private static async Task <byte[]> ReadFileBytes(Windows.Storage.StorageFile storageFile)
        {
            if (storageFile == null)
            {
                return(null);
            }

            using (var stream = await storageFile.OpenReadAsync())
            {
                using (DataReader reader = new DataReader(stream))
                {
                    var imageBytes = new byte[stream.Size];

                    await reader.LoadAsync((uint)imageBytes.Length);

                    reader.ReadBytes(imageBytes);

                    return(imageBytes);
                }
            }
        }
Esempio n. 19
0
        private async void btnStartStop_Click(object sender, RoutedEventArgs e)
        {
            if (isLooperRunning)
            {
                this.dt.Stop();
                this.isLooperRunning      = !this.isLooperRunning;
                this.btnStartStop.Content = "Start";
            }
            else
            {
                var          pauseInterval  = this.ReadPauseInterval();
                var          actionInterval = this.ReadActionInterval();
                MediaElement player         = new MediaElement();
                Windows.Storage.StorageFolder assetsFolder = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync("Assets");

                Windows.Storage.StorageFile sound = await assetsFolder.GetFileAsync("boom.wav");

                var soundStream = await sound.OpenReadAsync();

                player.SetSource(soundStream, "");

                if (actionInterval > 0)
                {
                    this.dt.Interval = TimeSpan.FromSeconds(actionInterval);
                    this.dt.Tick    += async(dtSender, dtEvents) =>
                    {
                        player.Play();
                        await Task.Delay(TimeSpan.FromSeconds(pauseInterval));

                        player.Play();
                    };

                    this.dt.Start();
                    this.isLooperRunning      = !this.isLooperRunning;
                    this.btnStartStop.Content = "Stop";
                }
            }
        }
Esempio n. 20
0
        public async Task UploadFile(Windows.Storage.StorageFile file)
        {
            var fileName = file.Name;

            using (Windows.Storage.Streams.IRandomAccessStreamWithContentType stream = await file.OpenReadAsync())
                await deviceClient.UploadToBlobAsync(fileName, stream.AsStream());
        }
Esempio n. 21
0
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            var picker = new Windows.Storage.Pickers.FileOpenPicker();

            picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;
            picker.FileTypeFilter.Add(".jpg");
            picker.FileTypeFilter.Add(".jpeg");
            picker.FileTypeFilter.Add(".png");
            picker.FileTypeFilter.Add(".gif");
            picker.FileTypeFilter.Add(".bmp");

            Windows.Storage.StorageFile file = await picker.PickSingleFileAsync();

            if (file == null)
            {
                return;
            }

            ClearResult();

            // 選択された画像ファイルからSoftwareBitmapを作る
            // https://docs.microsoft.com/ja-jp/windows/uwp/audio-video-camera/imaging
            SoftwareBitmap softwareBitmap;

            using (IRandomAccessStream stream = await file.OpenReadAsync())
            {
                BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream);

                softwareBitmap = await decoder.GetSoftwareBitmapAsync();
            }
            // Image コントロールは、BGRA8 エンコードを使用し、プリマルチプライ処理済みまたはアルファ チャネルなしの画像しか受け取れない
            // 異なるフォーマットの場合は変換する☟
            if (softwareBitmap.BitmapPixelFormat != BitmapPixelFormat.Bgra8 ||
                softwareBitmap.BitmapAlphaMode == BitmapAlphaMode.Straight)
            {
                softwareBitmap = SoftwareBitmap.Convert(softwareBitmap, BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied);
            }
            // ImageコントロールにはSoftwareBitmapSourceを渡す
            var source = new SoftwareBitmapSource();
            await source.SetBitmapAsync(softwareBitmap);

            this.Image1.Source = source;

            // バーコード読み取り
            ZXing.BarcodeReader _reader
                = new ZXing.BarcodeReader
                {
                AutoRotate = true,
                Options    = { TryHarder = true }
                };
            // UWPではSoftwareBitmapかWriteableBitmapを渡す
            //ZXing.Result result = _reader.Decode(softwareBitmap);
            // ☟別スレッドでやるときも、作成済みのSoftwareBitmapインスタンスを渡してよい
            ZXing.Result result
                = await Task.Run(() => _reader.Decode(softwareBitmap));

            if (result != null)
            {
                ShowResult(result);
            }
        }