// Read byte[] from png file
BinaryReader binReader = new BinaryReader(File.Open(filepath, FileMode.Open));
FileInfo fileInfo = new FileInfo(filepath);
byte[] bytes = binReader.ReadBytes((int)fileInfo.Length);
binReader.Close(); // Init bitmap
BitmapImage bitmap = new BitmapImage();
bitmap.BeginInit();
//bitmap.DecodePixelWidth = Convert.ToInt32(w);
//bitmap.DecodePixelHeight = Convert.ToInt32(h);
//bitmap.CacheOption = System.Windows.Media.Imaging.BitmapCacheOption.OnLoad;
//bitmap.CreateOptions = System.Windows.Media.Imaging.BitmapCreateOptions.IgnoreImageCache;
bitmap.StreamSource = new MemoryStream(bytes);
bitmap.EndInit();

System.Windows.Media.Imageing.BItmapImage 这么用才不会占用文件的更多相关文章

  1. 保存图片控件上的图片到本地 出现错误:无法将类型为“System.Windows.Media.Imaging.BitmapFrameDecode”的对象强制转换为类型“System.Windows.Media.Imaging.BitmapImage”。

    保存图片控件上的图片到本地 出现错误:无法将类型为“System.Windows.Media.Imaging.BitmapFrameDecode”的对象强制转换为类型“System.Windows.M ...

  2. WPF System.InvalidCastException: 无法将类型为“System.Windows.Media.Color”的对象强制转换为类型“System.Windows.Media.Brush”。

    场景:添加ComboBox样式,界面卡死,日志异常文件如下: -- ::, | ERROR | System.InvalidCastException: 无法将类型为“System.Windows.M ...

  3. C# Pen绘制虚线(System.Drawing.Pen与System.Windows.Media.Pen)

    一.绘制虚线的方法 GDI绘制,使用的是System.Drawing.Pen Pen pen = new Pen(Color.Red, 1);            pen.DashStyle = S ...

  4. WPF 问题 PresentationCore.dll!System.Windows.Media.Composition.DUCE.Channel.SyncFlush() 分析

    错误信息: 没有足够的内存继续执行程序 在 System.Windows.Media.Composition.DUCE.Channel.SyncFlush() 在 System.Windows.Int ...

  5. C# using System.Windows.Media.Imaging;该引用哪个dll

    在网上看到BitmapSource和WriteableBitmap一些类听说是用 using System.Windows.Media.Imaging:可是我发现VS中没有什么System.Windo ...

  6. 关于WPF System.windows.Media.FontFamily 的类型初始值设定项引发异常问题解决方法

    造成原因:此问题的根本原因是.NET Framework January 2018 Rollup(KB4055002)与已安装的.NET Framework 4.7.1产品版本之间的MSI安装交互.R ...

  7. WPF的System.Windows.Threading.DispatcherTimer的使用(每隔一定的时间重复做某事)

    这里使用了一个进度条来展示, 前段代码: <Window x:Class="TimerTest.MainWindow" xmlns="http://schemas. ...

  8. System.Windows.Forms.Control : Component, IOleControl, IOleObject, IOleInPlaceObject, IOleInPlaceActiveObject....

    #region 程序集 System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ...

  9. 与众不同 windows phone (13) - Background Task(后台任务)之后台文件传输(上传和下载)

    原文:与众不同 windows phone (13) - Background Task(后台任务)之后台文件传输(上传和下载) [索引页][源码下载] 与众不同 windows phone (13) ...

随机推荐

  1. json 解析 真是一篇让我泪流满面的好文章

    http://my.eoe.cn/iceskysl/archive/19629.html点击打开链接

  2. GDI+一般性错误(A generic error occurred in GDI+)

    1.GDI+的前世今生 GDI+全称图形设备接口,Graphics Device Interface (GDI) ,他的爸爸叫做GDI, 用C写的.Windows XP出来以后用C++重新写了一下,变 ...

  3. MYSQL 基于GTID的复制

    1.概述 从MYSQL5.6 开始,mysql开始支持GTID复制. 基于日志点复制的缺点: 从那个二进制日志的偏移量进行增量同步,如果指定错误会造成遗漏或者重复,导致数据不一致. 基于GTID复制: ...

  4. C语言基础--进制

    进制表示: // 1.默认就是10进制 ; // 2.在前面加上一个0就代表八进制 ; // %d是以十进制的方式输出一个整数 printf("%d\n", num1); // % ...

  5. 在standalone模式下运行yarn 0.9.0对HDFS上的数据进行计算

    1.通读http://spark.incubator.apache.org/docs/latest/spark-standalone.html 2.在每台机器上将spark安装到/opt/spark ...

  6. dom自定义属性 兼容 index值获取

    function getIndex(Eve,obj){ for(var i = 0;i<obj.length;i++){ obj[i].setAttribute("index" ...

  7. Introducing Windows 10 Editions(Windows10版本介绍)

    Windows 10将在今年夏天正式发布,今天微软官方博客分享了一些Windows 10版本的细节.详见Introducing Windows 10 Editions Windows 10 HomeW ...

  8. Python OpenCV —— bitwise

    关于图像的位操作,目的是为了将一个logo覆盖到另一个图片上. # -*- coding: utf-8 -*- """ Created on Wed Sep 28 20: ...

  9. 使用OpenXML操作Office文档

    使用OpenXML类库, 以编程的方式来访问PowerPoint, Word, Excel等文档, 有时能够为我们批量编辑文档提供方便. 最近项目中遇到的两个任务是: 1. 替换文档中的图片的Alt ...

  10. ubuntu14.04LTS编译MUDOS v22.2b14

    附:MudOS v22.2b14下载连接 简单的编译步骤: (1)运行./build.MudOS (2)vim socket_efuns.c       o 修改Ln:1198的代码为         ...