【WPF】WriteableBitmap和BitmapImage的相互转换
- public BitmapImage ConvertWriteableBitmapToBitmapImage(WriteableBitmap wbm)
- {
- BitmapImage bmImage = new BitmapImage();
- using (MemoryStream stream = new MemoryStream())
- {
- PngBitmapEncoder encoder = new PngBitmapEncoder();
- encoder.Frames.Add(BitmapFrame.Create(wbm));
- encoder.Save(stream);
- bmImage.BeginInit();
- bmImage.CacheOption = BitmapCacheOption.OnLoad;
- bmImage.StreamSource = stream;
- bmImage.EndInit();
- bmImage.Freeze();
- }
- return bmImage;
- }
- public static class ImageHelpers
- {
- public static BitmapImage ToBitmapImage(this WriteableBitmap wbm)
- {
- BitmapImage bmImage = new BitmapImage();
- using (MemoryStream stream = new MemoryStream())
- {
- PngBitmapEncoder encoder = new PngBitmapEncoder();
- encoder.Frames.Add(BitmapFrame.Create(wbm));
- encoder.Save(stream);
- bmImage.BeginInit();
- bmImage.CacheOption = BitmapCacheOption.OnLoad;
- bmImage.StreamSource = stream;
- bmImage.EndInit();
- bmImage.Freeze();
- }
- return bmImage;
- }
- }
以上一个普通方法,第二个则是扩展方法。
【WPF】WriteableBitmap和BitmapImage的相互转换的更多相关文章
- GDI+ Bitmap与WPF BitmapImage的相互转换
原文:GDI+ Bitmap与WPF BitmapImage的相互转换 using System.Windows.Interop; //... // Convert BitmapImage to Bi ...
- win10 uwp 读取保存WriteableBitmap 、BitmapImage
我们在UWP,经常使用的图片,数据结构就是 BitmapImage 和 WriteableBitmap.关于 BitmapImage 和 WriteableBitmap 区别,我就不在这里说.主要说的 ...
- WPF中使用BitmapImage处理图片文件(转)
(1)图片从文件导入 BitmapImage image = new BitmapImage(); image.BeginInit(); image.UriSource = new Uri(filen ...
- 【C#/WPF】保存BitmapImage数据到文件中
参考: http://stackoverflow.com/questions/35804375/how-do-i-save-a-bitmapimage-from-memory-into-a-file- ...
- WPF bitmap转bitmapimage 使用 CreateBitmapSourceFromHBitmap内存泄漏
IntPtr f = bmp.GetHbitmap(); img.Source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitm ...
- 【转】【WPF】WriteableBitmap应用及图片数据格式转换
使用 WriteableBitmap 类基于每个框架来更新和呈现位图.这对于生成算法内容(如分形图像)和数据可视化(如音乐可视化工具)很有用. WriteableBitmap 类使用两个缓冲区.“后台 ...
- 【C#/WPF】Bitmap、BitmapImage、ImageSource 、byte[]转换问题
C#/WPF项目中,用到图像相关的功能时,涉及到多种图像数据类型的相互转换问题,这里做了个整理.包含的内容如下: Bitmap和BitmapImage相互转换. RenderTargetBitmap ...
- WriteableBitmap/BitmapImage/MemoryStream/byte[]相互转换
1 WriteableBitmap/BitmapImage/MemoryStream/byte[]相互转换 2012-12-18 17:27:04| 分类: Windows Phone 8|字号 订 ...
- 【WPF/C#】联网异步获取二进制文件(如图片)的流程
步骤: 联网异步获取Json数据. 使用Json.NET工具,反序列化Json为对应的实体类,获得该实体类的对象. 从对象身上获取图片路径(实体类中定义了头像图片是string类型的文件路径). 根据 ...
随机推荐
- array_intersect
<?php date_default_timezone_set('Asia/Shanghai'); $a1=array("a"=>"red",&qu ...
- spring boot 2.0.3+spring cloud (Finchley)9、 安全组件Spring Boot Security
官方文档 一.Spring Security介绍 Spring Security是Spring Resource社区的一个安全组件,Spring Security为JavaEE企业级开发提供了全面的安 ...
- 主席树 或者 离散化+分块 BZOJ 4636
4636: 蒟蒻的数列 Time Limit: 30 Sec Memory Limit: 256 MBSubmit: 381 Solved: 177[Submit][Status][Discuss ...
- 数学&动态规划:期望DP
BZOJ3036 给定一张有向无环图,起点为1,终点为N,每个点i有ki条出边,从每个点走其中一条出边的概率是1/ki,求从1到N的期望步数 我们注意到一点,走每条边都是等概率的,那么就相当于 给定一 ...
- System Administrator(构造,图论)
System Administrator time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- 51nod 1161 Partial Sums
给出一个数组A,经过一次处理,生成一个数组S,数组S中的每个值相当于数组A的累加,比如:A = {1 3 5 6} => S = {1 4 9 15}.如果对生成的数组S再进行一次累加操作,{1 ...
- php跳转网络连接
laravel用 redirect 跳转 HTTP 即可.可以把网址看作路由 例如: if($newsInfo->type == 77){ return redirect('http://192 ...
- 【leetcode 简单】第十一题 搜索插入位置
给定一个排序数组和一个目标值,在数组中找到目标值,并返回其索引.如果目标值不存在于数组中,返回它将会被按顺序插入的位置. 你可以假设数组中无重复元素. 示例 1: 输入: [1,3,5,6], 5 输 ...
- 从ZoomEye API 到 Weblogic 弱口令扫描
参考资料: ZoomEye API: https://www.zoomeye.org/api/doc Weblogic-Weakpassword-Scnner: https://github.com/ ...
- NYOJ 328 完全覆盖 (找规律)
题目链接 描述 有一天小董子在玩一种游戏----用21或12的骨牌把mn的棋盘完全覆盖.但他感觉游戏过于简单,于是就随机生成了两个方块的位置(可能相同),标记一下,标记后的方块不用覆盖.还要注意小董子 ...