【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类型的文件路径). 根据 ...
随机推荐
- Ubuntu+NDK编译支持HTTPS的libcurl
参考文章:1.NDK环境配置 http://blog.csdn.net/smfwuxiao/article/details/65877092.libcurl的配置修改 http://piggyq.co ...
- Vue2.0中的路由配置
Vue2.0较Vue1.0,路由有了较大改变.看一下Vue2.0中的路由如何配置: 步骤一: 在main.js文件中引入相关模块以及组件及实例化vue对象配置选项路由及渲染App组件 默认设置如下: ...
- Scrapy的安装--------Windows、linux、mac等操作平台
Scrapy安装 Scrapy的安装有多种方式,它支持Python2.7版本及以上或者是Python3.3版本及以上.下面来说py3环境下,scrapy的安装过程. Scrapy依赖的库比较多,至少需 ...
- JSOI2008 小店购物
https://www.luogu.org/problem/show?pid=2792 题目背景 JSOI集训队的队员发现,在他们经常活动的集训地,有一个小店因为其丰富的经营优惠方案深受附近居民的青睐 ...
- 2-sat 分类讨论 UVALIVE 3713
蓝书326 //看看会不会爆int!数组会不会少了一维! //取物问题一定要小心先手胜利的条件 #include <bits/stdc++.h> using namespace std; ...
- php输出日志的实现
php输出日志的实现 思想:在想要输出log日志的地方,使用php的写入文件函数,把数据写入到事先定义好的文件中. php代码如下: //输出日志 public function outputLog( ...
- PHP脚本运行时间
http://www.cnblogs.com/zqifa/p/php-16.html PHP设置脚本最大执行时间的三种方法 php.ini 中缺省的最长执行时间是 30 秒,这是由 php.ini 中 ...
- 【leetcode 简单】第三十二题 买卖股票的最佳时机Ⅱ
给定一个数组,它的第 i 个元素是一支给定股票第 i 天的价格. 设计一个算法来计算你所能获取的最大利润.你可以尽可能地完成更多的交易(多次买卖一支股票). 注意:你不能同时参与多笔交易(你必须在再次 ...
- Test plan
Options for Test Strategy: 1. Regular test: all the planned test cases will be executed 2. Extented ...
- Spring Boot企业级博客系统实战视频教程
欢迎关注我的微信公众号:"Java面试通关手册" 回复关键字" springboot "免费领取(一个有温度的微信公众号,期待与你共同进步~~~坚持原创,分享美 ...