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. easyUI设置textbox的值

    我们知道<input type="text" class="easyui-validatebox" id="txtrName" nam ...

  2. C++ 虚函数表浅析

    一.背景知识(一些基本概念) 虚函数(Virtual Function):在基类中声明为 virtual 并在一个或多个派生类中被重新定义的成员函数. 纯虚函数(Pure Virtual Functi ...

  3. 64位FreeSWITCH编译安装(版本1.4.20)

    1.安装64位的CentOS6.5操作系统(勾选的服务器版本安装). 2.下载FreeSWITCH安装包以及关联的lib库.下载地址http://files.freeswitch.org/downlo ...

  4. ADS错误the session file 'C:\user\username\default-1-2-0-0.ses' could not be loaded解决办法

    问题描述:用ADS1.2 + H-JTAG或者是H-Jlink,每次调试的时候都会出现“the session file could not be loaded”这个错误,寻求解决办法?问题解答:用户 ...

  5. Java:多线程,CountDownLatch同步器

    1. 背景 CountDownLatch类,在完成一组正在其他线程中执行的操作之前,它允许一个或多个线程一直等待. 用给定的计数 初始化 CountDownLatch.由于调用了 countDown( ...

  6. 对于在Android Studio 的 build.gradle 中的默认applicationId 要不要写呢?

    起因 刚完成一个版本的开发.刚上Google play 就有用户反映无法更新应用.错误代码为:Can't install app "****" can' be installed. ...

  7. iPhone:动态获取UILabel的高度和宽度

    转自:http://www.cnblogs.com/spiritstudio/archive/2011/11/17/2252074.html 在使用UILabel存放字符串时,经常需要获取label的 ...

  8. golang bufio、ioutil读文件的速度比较(性能测试)和影响因素分析

    前言 golang读取文件的方式主要有4种: 使用File自带的Read方法 使用bufio库的Read方法 使用io/ioutil库的ReadAll() 使用io/ioutil库的ReadFile( ...

  9. hdu 3371 Connect the Cities(最小生成树)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=3371 984ms风险飘过~~~ /************************************ ...

  10. Google MapReduce到底解决什么问题?

    很多时候,定义清楚问题比解决问题更难. 什么是MapReduce? 它不是一个产品,而是一种解决问题的思路,它有多个工程实现,Google在论文中也给出了它自己的工程架构实现. MapReduce这个 ...