當前位置: 首頁>>代碼示例>>C#>>正文


C# WriteableBitmap.ToStreamAsJpeg方法代碼示例

本文整理匯總了C#中Windows.UI.Xaml.Media.Imaging.WriteableBitmap.ToStreamAsJpeg方法的典型用法代碼示例。如果您正苦於以下問題:C# WriteableBitmap.ToStreamAsJpeg方法的具體用法?C# WriteableBitmap.ToStreamAsJpeg怎麽用?C# WriteableBitmap.ToStreamAsJpeg使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Windows.UI.Xaml.Media.Imaging.WriteableBitmap的用法示例。


在下文中一共展示了WriteableBitmap.ToStreamAsJpeg方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: SaveImageAsync

        private async Task SaveImageAsync(WriteableBitmap bitmap)
        {
            var folder = KnownFolders.PicturesLibrary;
            var file = await folder.CreateFileAsync("placa.jpeg", CreationCollisionOption.GenerateUniqueName);

            using (var stream = await file.OpenAsync(FileAccessMode.ReadWrite))
            {
                await bitmap.ToStreamAsJpeg(stream);
            }
        }
開發者ID:andremn,項目名稱:SPS,代碼行數:10,代碼來源:PlateRecognizer.cs

示例2: GetPixels

        private static async Task<Color> GetPixels(WriteableBitmap bitmap, Color[] pixels, Int32 width, Int32 height)
        {
            IRandomAccessStream bitmapStream = new InMemoryRandomAccessStream();
            await bitmap.ToStreamAsJpeg(bitmapStream);
            var bitmapDecoder = await BitmapDecoder.CreateAsync(bitmapStream);
            var pixelProvider = await bitmapDecoder.GetPixelDataAsync();
            Byte[] byteArray = pixelProvider.DetachPixelData();
            Int32 r = 0, g = 0, b = 0;
            int sum = pixels.Length;
            for (var i = 0; i < height; i++)
            {
                for (var j = 0; j < width; j++)
                {

                    r += byteArray[(i * width + j) * 4 + 2];
                    g += byteArray[(i * width + j) * 4 + 1];
                    b += byteArray[(i * width + j) * 4 + 0];
                }
            }
            return Color.FromArgb((byte)(255), (byte)(r / sum), (byte)(g / sum), (byte)(b / sum));
        }
開發者ID:aurora-lzzp,項目名稱:com.aurora.aumusic,代碼行數:21,代碼來源:BitmapHelper.cs

示例3: GetPixels

        public static async Task GetPixels(WriteableBitmap bitmap, Color[] pixels, Int32 width, Int32 height)
        {
            IRandomAccessStream bitmapStream = new InMemoryRandomAccessStream();
            await bitmap.ToStreamAsJpeg(bitmapStream);

            var bitmapDecoder = await BitmapDecoder.CreateAsync(bitmapStream);
            var pixelProvider = await bitmapDecoder.GetPixelDataAsync();
            Byte[] byteArray = pixelProvider.DetachPixelData();

            for (var i = 0; i < height; i++)
            {
                for (var j = 0; j < width; j++)
                {
                    Int32 r = byteArray[(i * height + j) * 4 + 2];
                    Int32 g = byteArray[(i * height + j) * 4 + 1];
                    Int32 b = byteArray[(i * height + j) * 4 + 0];

                    pixels[(i * height + j)] = Color.FromArgb(0xFF, (byte)r, (byte)g, (byte)b);
                }
            }
        }
開發者ID:renewal-wu,項目名稱:PaletteSample,代碼行數:21,代碼來源:Palette.cs

示例4: LoadWallpaperArt


//.........這裏部分代碼省略.........
                    .Take(numImages > albumCount ? albumCount : numImages)
                    .ToList());

                if (imagesNeeded > 0)
                {
                    var repeatList = new List<Album>();

                    while (imagesNeeded > 0)
                    {
                        var takeAmmount = imagesNeeded > albumCount ? albumCount : imagesNeeded;

                        await Task.Run(() => repeatList.AddRange(shuffle.Shuffle().Take(takeAmmount)));

                        imagesNeeded -= shuffle.Count;
                    }

                    shuffle.AddRange(repeatList);
                }

                // Initialize an empty WriteableBitmap.
                var destination = new WriteableBitmap((int) Window.Current.Bounds.Width,
                    (int) Window.Current.Bounds.Height);
                var col = 0; // Current Column Position
                var row = 0; // Current Row Position
                destination.Clear(Colors.Black); // Set the background color of the image to black

                // will be copied
                foreach (var artworkPath in shuffle.Select(album => string.Format(AppConstant.ArtworkPath, album.Id)))
                {
                    var file = await WinRtStorageHelper.GetFileAsync(artworkPath);

                    // Read the image file into a RandomAccessStream
                    using (var fileStream = await file.OpenReadAsync())
                    {
                        try
                        {
                            // Now that you have the raw bytes, create a Image Decoder
                            var decoder = await BitmapDecoder.CreateAsync(fileStream);

                            // Get the first frame from the decoder because we are picking an image
                            var frame = await decoder.GetFrameAsync(0);

                            // Convert the frame into pixels
                            var pixelProvider = await frame.GetPixelDataAsync();

                            // Convert pixels into byte array
                            var srcPixels = pixelProvider.DetachPixelData();
                            var wid = (int) frame.PixelWidth;
                            var hgt = (int) frame.PixelHeight;
                            // Create an in memory WriteableBitmap of the same size
                            var bitmap = new WriteableBitmap(wid, hgt); // Temporary bitmap into which the source

                            using (var pixelStream = bitmap.PixelBuffer.AsStream())
                            {
                                pixelStream.Seek(0, SeekOrigin.Begin);
                                // Push the pixels from the original file into the in-memory bitmap
                                await pixelStream.WriteAsync(srcPixels, 0, srcPixels.Length);
                                bitmap.Invalidate();

                                // Resize the in-memory bitmap and Blit (paste) it at the correct tile
                                // position (row, col)
                                destination.Blit(new Rect(col*albumSize, row*albumSize, albumSize, albumSize),
                                    bitmap.Resize(albumSize, albumSize, WriteableBitmapExtensions.Interpolation.Bilinear),
                                    new Rect(0, 0, albumSize, albumSize));
                                col++;
                                if (col < collumns) continue;

                                row++;
                                col = 0;
                            }
                        }
                        catch
                        {
                            // ignored
                        }
                    }
                }

                var wallpaper =
                    await WinRtStorageHelper.CreateFileAsync("wallpaper.jpg", ApplicationData.Current.LocalFolder);
                using (var rndWrite = await wallpaper.OpenAsync(FileAccessMode.ReadWrite))
                {
                    await destination.ToStreamAsJpeg(rndWrite);
                }

                App.Locator.AppSettingsHelper.WriteAsJson("WallpaperCreated", DateTime.Now);
                // If there are 30 or less albums then recreate in one day, else wait a week
                App.Locator.AppSettingsHelper.Write("WallpaperDayWait", albums.Count < 30 ? 1 : 7);

                imageBrush.ImageSource = null;
                imageBrush.ImageSource = new BitmapImage(new Uri("ms-appdata:/local/wallpaper.jpg"));
            }
            else if (created != DateTime.MinValue)
            {
                // Not the first time, so there must already be one created
                imageBrush.ImageSource = new BitmapImage(new Uri("ms-appdata:/local/wallpaper.jpg"));
            }

            _loaded = true;
        }
開發者ID:jayharry28,項目名稱:Audiotica,代碼行數:101,代碼來源:CollectionPage.xaml.cs


注:本文中的Windows.UI.Xaml.Media.Imaging.WriteableBitmap.ToStreamAsJpeg方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。