1 WriteableBitmap/BitmapImage/MemoryStream/byte[]相互转换

2012-12-18 17:27:04|  分类: Windows Phone 8|字号 订阅

 
 

,WriteableBitmap与BitmapImage转换

1.1 BitmapImage  to WriteableBitmap

BitmapImage bitmapImage=new BitmapImage(new Uri(“http://...”,UriKind.Revelate));

WriteableBitmap writeableBitmap = new WriteableBitmap(bitmapImage);

1.2 WriteableBitmap to BitmapImage

MemoryStream stream = new MemoryStream();

writeableBitmap.SaveJpeg(stream, writeableBitmap.PixelWidth,

writeableBitmap.PixelHeight,0,100);

BitmapImage temp = new BitmapImage();

temp.SetSource(stream);

,WriteableBitmap/BitmapImage to byte[]

2.1 WriteableBitmap to byte[]

MemoryStream stream = new MemoryStream();

writeableBitmap.SaveJpeg(stream, writeableBitmap.PixelWidth,

writeableBitmap.PixelHeight,0,100);

byte[]rgbBytes = stream.ToArray();

2.2 byte[] to WriteableBitmap

byte[]rgbBytes;

MemoryStream stream = new MemoryStream(rgbBytes);

WriteableBitmap writeableBitmap = new WriteableBitmap(width,height);

writeableBitmap.LoadJpeg(stream);

2.3 BitmapImage to byte[]

BitmapImage bitmapImage=new BitmapImage(new Uri(“http://...”,UriKind.Revelate));

WriteableBitmap writeableBitmap = new WriteableBitmap(bitmapImage);

MemoryStream stream = new MemoryStream();

writeableBitmap.SaveJpeg(stream, writeableBitmap.PixelWidth,

writeableBitmap.PixelHeight,0,100);

byte[]rgbBytes = stream.ToArray();

2.4 byte[] to BitmapImage

byte[]rgbBytes;

MemoryStream stream = new MemoryStream(rgbBytes);

BitmapImage bitmapImage = new BitmapImage();

bitmapImage.SetSource(stream);

,WriteableBitmap/BitmapImage to stream

3.1 WriteableBitmap to stream

MemoryStream stream = new MemoryStream();

writeableBitmap.SaveJpeg(stream, writeableBitmap.PixelWidth,

writeableBitmap.PixelHeight,0,100);

3.2 MemoryStream to WriteableBitmap

BitmapImage bitmapImage = new BitmapImage();

bitmapImage.SetSource(memoryStream);

WriteableBitmap writeableBitmap = new WriteableBitmap (bitmapImage);

3.3 BitmapImage to MemoryStream

BitmapImage bitmapImage;

WriteableBitmap writeableBitmap = new WriteableBitmap(bitmapImage);

MemoryStream stream = new MemoryStream();

writeableBitmap.SaveJpeg(stream, writeableBitmap.PixelWidth, writeableBitmap.PixelHeight,0,100);

3.4 MemoryStream to BitmapImage

BitmapImage bitmapImage = new BitmapImage();

bitmapImage.SetSource(stream);

WriteableBitmap/BitmapImage/MemoryStream/byte[]相互转换的更多相关文章

  1. Silverlight中将WriteableBitmap互转byte数组

    //WriteableBitmap to ARGB ;    , result, , len);    , bmp.Pixels, , buffer.Length); }

  2. dword word byte 相互转换 .xml

    pre{ line-height:1; color:#800080; background-color:#d2c39b; font-size:16px;}.sysFunc{color:#627cf6; ...

  3. C#中string和byte[]相互转换问题解决

    本来想讲string转换为byte数组,通过在VS上打 ‘str. “来找,结果半天没发现跳出来的函数中有想要的,哭瞎 /(ㄒoㄒ)/~~ 这回将两种情况都记下来了.... string ---> ...

  4. java 中 image 和 byte[] 相互转换

      java 中 image 和 byte[] 相互转换可恶的…………其实也挺好的 只是把好不容易写出来的东西记下来,怕忘了…… 下面,我来介绍一个简单的 byte[] to image, 我们只需要 ...

  5. [uwp]ImageSource和byte[]相互转换

    最近做一个小app遇到一个问题,到目前还没有比较好的解决方法(可能是我查的资料不够多) 需求如下: 1.把一个Image中的图像保存到字节数组: 2.把字节数组转换为ImageSource,通过Ima ...

  6. C#图像处理:Stream 与 byte[] 相互转换,byte[]与string,Stream 与 File 相互转换等

    C# Stream 和 byte[] 之间的转换 一. 二进制转换成图片 MemoryStream ms = new MemoryStream(bytes); ms.Position = 0; Ima ...

  7. C# 文件、byte相互转换

    文件转byte数组: /// <summary> /// 将文件转换为byte数组 /// </summary> /// <param name="path&q ...

  8. 图片与byte相互转换

    一.图片转byte public byte[] ImageToByte() { string imagefile = @"http://192.168.0.212/pass/T-1.jpg& ...

  9. String 与 byte[]相互转换

    1. 从byte[]转换成string string result = System.Text.Encoding.UTF8.GetString(byteArray); 2.从string 转换成byt ...

随机推荐

  1. 【jsp】怎么在jsp文件中引入静态文件(.js .css)

    如果在jsp文件中引入静态文件比如(.js或.css等等),可以在使用 /项目名称/路径 的方式,但是这种方式如果在修改了项目了名称后就显得比较麻烦了.除了之外还许多方式,比如相对路径等等.一般情况下 ...

  2. hibernate使用注解设置日期默认值

    用注解设置属性的默认值时 使用 @Temporal(TemporalType.TIMESTAMP) @Column(updatable = false,nullable=false,length=20 ...

  3. 绿色版mysql注册卸载服务

    如果直接用绿色版的mysql,则下载后解压,只需对目录下的my.ini文件的basedir(mysql的基本目录)和datadir(mysql数据目录)指定就可以,如下所示. #Path to ins ...

  4. systemctl 命令

    systemctl命令是系统服务管理器指令,它实际上将 service 和 chkconfig 这两个命令组合到一起. 任务 旧指令 新指令 使某服务自动启动 chkconfig --level 3 ...

  5. LeetCode[Linked List]: Remove Duplicates from Sorted List II

    Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numb ...

  6. python标准库介绍——37 signal 模块详解

    ==signal 模块== 你可以使用 ``signal`` 模块配置你自己的信号处理器 (signal handler), 如 [Example 3-11 #eg-3-11] 所示. 当解释器收到某 ...

  7. django -- while time zone support is active

    一.先看报错: django 在处理datetime类型的的报错/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site ...

  8. [hihoCoder] 第四十八周: 拓扑排序·二

    题目1 : 拓扑排序·二 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho所在学校的校园网被黑客入侵并投放了病毒.这事在校内BBS上立刻引起了大家的讨论,当 ...

  9. 菜鸟调错(五)——jetty运行时无法保存文件

    背景交代: 上一篇博客写的是用jetty和Maven做开发.测试.在使用的过程中遇到一个小问题,就是在jetty启动以后,修改了jsp.xml等文件无法保存. 错误信息: 解决方案: 到Maven库( ...

  10. 2-2-求并集A=A∪B-线性表-第2章-《数据结构》课本源码-严蔚敏吴伟民版

    课本源码部分 第2章  线性表 - 求并集A=A∪B ——<数据结构>-严蔚敏.吴伟民版        ★有疑问先阅读★ 源码使用说明  链接☛☛☛ <数据结构-C语言版>(严 ...