private async System.Threading.Tasks.Task LoadSampleImage(string fileName)
        {
            var sampleUri = new Uri("ms-appx:///Sample/" + fileName);
            var file      = await Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(sampleUri);

            _bitmap = await LoadImageAsync(file);

            this.SampleImage.Source = _bitmap;
        }
Beispiel #2
0
      // Unity3D
#endif

#if NETFX_CORE
      public Windows.UI.Xaml.Media.Imaging.WriteableBitmap ToBitmap()
      {
         var bmp = new Windows.UI.Xaml.Media.Imaging.WriteableBitmap(Width, Height);
         using (var stream = System.Runtime.InteropServices.WindowsRuntime.WindowsRuntimeBufferExtensions.AsStream(bmp.PixelBuffer))
         {
            stream.Write(Pixels, 0, Pixels.Length);
         }
         bmp.Invalidate();
         return bmp;
      }
Beispiel #3
0
        // Unity3D
#endif

#if NETFX_CORE
        public Windows.UI.Xaml.Media.Imaging.WriteableBitmap ToBitmap()
        {
            var bmp = new Windows.UI.Xaml.Media.Imaging.WriteableBitmap(Width, Height);

            using (var stream = System.Runtime.InteropServices.WindowsRuntime.WindowsRuntimeBufferExtensions.AsStream(bmp.PixelBuffer))
            {
                stream.Write(Pixels, 0, Pixels.Length);
            }
            bmp.Invalidate();
            return(bmp);
        }
        LoadImageAsync(Windows.Storage.StorageFile file)
        {
            Windows.Storage.FileProperties.ImageProperties imgProp = await file.Properties.GetImagePropertiesAsync();

            using (var imgStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read))
            {
                var bitmap = new Windows.UI.Xaml.Media.Imaging.WriteableBitmap((int)imgProp.Width, (int)imgProp.Height);
                bitmap.SetSource(imgStream);
                return(bitmap);
            }
        }
Beispiel #5
0
        private static async Task <BandIcon> LoadIcon(string uri)
        {
            StorageFile imageFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri(uri));

            using (IRandomAccessStream fileStream = await imageFile.OpenAsync(FileAccessMode.Read))
            {
                Windows.UI.Xaml.Media.Imaging.WriteableBitmap bitmap = new Windows.UI.Xaml.Media.Imaging.WriteableBitmap(1, 1);
                await bitmap.SetSourceAsync(fileStream);

                return(bitmap.ToBandIcon());
            }
        }
Beispiel #6
0
        public async Task<string> clipboard(DataPackageView con)
        {
            string str = string.Empty;
            //文本
            if (con.Contains(StandardDataFormats.Text))
            {
                str = await con.GetTextAsync();
                return str;
            }

            //图片
            if (con.Contains(StandardDataFormats.Bitmap))
            {
                RandomAccessStreamReference img = await con.GetBitmapAsync();
                var imgstream = await img.OpenReadAsync();
                Windows.UI.Xaml.Media.Imaging.BitmapImage bitmap = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
                bitmap.SetSource(imgstream);

                Windows.UI.Xaml.Media.Imaging.WriteableBitmap src = new Windows.UI.Xaml.Media.Imaging.WriteableBitmap(bitmap.PixelWidth, bitmap.PixelHeight);
                src.SetSource(imgstream);

                Windows.Graphics.Imaging.BitmapDecoder decoder = await Windows.Graphics.Imaging.BitmapDecoder.CreateAsync(imgstream);
                Windows.Graphics.Imaging.PixelDataProvider pxprd = await decoder.GetPixelDataAsync(Windows.Graphics.Imaging.BitmapPixelFormat.Bgra8, Windows.Graphics.Imaging.BitmapAlphaMode.Straight, new Windows.Graphics.Imaging.BitmapTransform(), Windows.Graphics.Imaging.ExifOrientationMode.RespectExifOrientation, Windows.Graphics.Imaging.ColorManagementMode.DoNotColorManage);
                byte[] buffer = pxprd.DetachPixelData();

                str = "image";
                StorageFolder folder = await _folder.GetFolderAsync(str);

                StorageFile file = await folder.CreateFileAsync(DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + (ran.Next() % 10000).ToString() + ".png", CreationCollisionOption.GenerateUniqueName);

                using (var fileStream = await file.OpenAsync(FileAccessMode.ReadWrite))
                {
                    var encoder = await Windows.Graphics.Imaging.BitmapEncoder.CreateAsync(Windows.Graphics.Imaging.BitmapEncoder.PngEncoderId, fileStream);
                    encoder.SetPixelData(Windows.Graphics.Imaging.BitmapPixelFormat.Bgra8, Windows.Graphics.Imaging.BitmapAlphaMode.Straight, decoder.PixelWidth, decoder.PixelHeight, decoder.DpiX, decoder.DpiY, buffer);
                    await encoder.FlushAsync();

                    str = $"![这里写图片描述](image/{file.Name})\n";
                }
            }

            //文件
            if (con.Contains(StandardDataFormats.StorageItems))
            {
                var filelist = await con.GetStorageItemsAsync();
                StorageFile file = filelist.OfType<StorageFile>().First();
                return await imgfolder(file);
            }

            return str;
        }
        private async Task <Windows.UI.Xaml.Media.Imaging.WriteableBitmap> DoCaptureWebView()
        {
            RingContentVisibility = true;

            InMemoryRandomAccessStream ms = new InMemoryRandomAccessStream();
            await _webview.CapturePreviewToStreamAsync(ms);

            int screenHeight = (int)_webview.ActualHeight;
            int screenWidth  = (int)_webview.ActualWidth;

            Windows.UI.Xaml.Media.Imaging.WriteableBitmap wb = await HeatMapFunctions.Resize(screenWidth, screenHeight, ms);

            RingContentVisibility = false;

            return(wb);
        }
Beispiel #8
0
        /// <summary>
        /// Load up an icon (png) file and convert it to an actual BandIcon object to be used with creating a new tile.
        /// </summary>
        /// <param name="url"> Url to the icon</param>
        /// <returns></returns>
        private async Task <BandIcon> LoadIcon(string url)
        {
            //Get the Image file from disk.
            Windows.Storage.StorageFile iconFile = await Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(new Uri(url));

            //Open up the file for random access (but stay with read>)
            using (Windows.Storage.Streams.IRandomAccessStream fileStream = await iconFile.OpenAsync(Windows.Storage.FileAccessMode.Read))
            {
                //Create a new bitmap
                Windows.UI.Xaml.Media.Imaging.WriteableBitmap iconWriteableBitmap = new Windows.UI.Xaml.Media.Imaging.WriteableBitmap(1, 1);

                //Process the picture to useable bitmap.
                await iconWriteableBitmap.SetSourceAsync(fileStream);

                //Extension method is written to convert a bitmap to an BandIcon that we can use with the Band
                return(iconWriteableBitmap.ToBandIcon());
            }
        }
        public QRkodVM(NavigationService _navigationService, object _arg)
        {
            var barcodeWriter = new BarcodeWriter
            {
                Format  = ZXing.BarcodeFormat.QR_CODE,
                Options = new ZXing.Common.EncodingOptions
                {
                    Width  = 300,
                    Height = 300,
                    Margin = 30
                }
            };
            string nesto = DateTime.Now.ToString("h:mm:ss tt");
            var    image = barcodeWriter.Write("Dzenitajfkjajflakglfkljkklgkdslg");

            slikica = barcodeWriter.Write("Dzenita");
            // var image = barcodeWriter.Write((string)_arg);
            //slikica =barcodeWriter.Write((string)_arg);
        }
        ExtractTextAsync(Windows.UI.Xaml.Media.Imaging.WriteableBitmap bitmap,
                         WindowsPreview.Media.Ocr.OcrLanguage language)
        {
            // OcrEngineオブジェクトを生成する
            var ocrEngine = new WindowsPreview.Media.Ocr.OcrEngine(language);

            // OcrEngineに画像を渡して、文字列を認識させる
            var ocrResult = await ocrEngine.RecognizeAsync(
                (uint)bitmap.PixelHeight,                   // 画像の高さ
                (uint)bitmap.PixelWidth,                    // 画像の幅
                bitmap.PixelBuffer.ToArray()                // 画像のデータ(バイト配列)
                );

            if (ocrResult.Lines == null || ocrResult.Lines.Count == 0)
            {
                this.ReadText.Text = "(何も読み取れませんでした)";
                return;
            }

            // Word間の区切り(日本語では無し、英語ではスペースとする)
            var separater = string.Empty;

            if (language == WindowsPreview.Media.Ocr.OcrLanguage.English)
            {
                separater = " ";
            }

            // 結果を表示するテキストボックスをクリアする
            this.ReadText.Text = string.Empty;

            // 行番号(0始まり)を定義
            int lineIndex = 0;

            // 認識結果を行ごとに処理する
            foreach (var line in ocrResult.Lines)
            {
                // 1行分の文字列を格納するためのバッファ
                var sb = new System.Text.StringBuilder();

                // 認識結果の行を、Wordごとに処理する
                foreach (var word in line.Words)
                {
                    // 認識した文字列をバッファに追加していく
                    sb.Append(word.Text);
                    sb.Append(separater);

                    // word は OcrWord 型。Textプロパティ(string型)の他に、
                    // その文字列を読み取った場所を表すLeft/Top/Widht/Heightプロパティ(int型)も持っている。
                    // なお、OcrWord という名前だが、日本語では1文字になる。
                }

                // ここでは、読み取った1行を以下のフォーマットで表示することにした
                this.ReadText.Text += string.Format("[{0}{1}] {2}{3}",
                                                    (lineIndex++).ToString(),    // 行番号(0始まり)
                                                    line.IsVertical ? "V" : "H", // 縦書き/横書きの区別
                                                    sb.ToString().TrimEnd(),     // 読み取った文字列
                                                    Environment.NewLine          // 改行
                                                    );
            }

            // 他に ocrResult.TextAngle (読み取った文字列群の、水平(または垂直)からの回転角度) も取得できる。
            // OcrWord 型の示す場所は、この TextAngle の分だけ回転している。
        }