设为首页 加入收藏

TOP

UWP开发中两种网络图片缓存方法(二)
2017-10-11 14:35:42 】 浏览:8638
Tags:UWP 开发 网络 图片 方法
stream); Stream pixelStream
= image.PixelBuffer.AsStream(); byte[] pixels = new byte[pixelStream.Length]; await pixelStream.ReadAsync(pixels, 0, pixels.Length); encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Ignore, (uint)image.PixelWidth, (uint)image.PixelHeight, 96.0, 96.0, pixels); await encoder.FlushAsync(); } } catch { } }
public async Task WriteToFileAsync(StorageFolder folder,SoftwareBitmap sb,string fileName)
        {
           
            if (sb != null)
            {
                // save image file to cache
                StorageFile file = await folder.CreateFileAsync(fileName, CreationCollisionOption.OpenIfExists);
                using (IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.ReadWrite))
                {
                    BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, stream);
                    encoder.SetSoftwareBitmap(sb);
                    await encoder.FlushAsync();
                }
            }
        }

怎么样,是不是很简单?

首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇UWP 律师信息 MVVM 2.0版本 下一篇[UWP] 自定义一个ItemsPanel

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目