WP7串流并返回 [英] WP7 string to stream and back
问题描述
大家好...
我正在Windows Phone 7中工作,我需要将字符串转换为流.
我得到了一个照片流,并已将其转换为字符串as-
hye all...
i m working in Windows Phone 7 and i need to convert a string to a stream.
i got a photo stream to which i have converted into string as-
StreamReader sr = new StreamReader(photoStream);
string str = sr.ReadToEnd();
现在我想将该字符串转换回流,然后将图像转换为-
now i want to convert that string back to stream and then to image as -
byte[] data = Encoding.UTF8.GetBytes(str);
MemoryStream memStream = new MemoryStream(data);
memStream.Seek(data.Length, 0);
WriteableBitmap bimg = PictureDecoder.DecodeJpeg(memStream);
image1.Source = bimg;
但随着它的来临
WriteableBitmap bimg = PictureDecoder.DecodeJpeg(memStream);
它给出了异常-参数不正确."
现在我该怎么办...:confused:
请帮忙...
在此先感谢...
but as it come to the line
WriteableBitmap bimg = PictureDecoder.DecodeJpeg(memStream);
it gives the exception - "The parameter is incorrect."
now what should i do...:confused:
please help...
thanks in advance...
推荐答案
如果这是图像数据,则我不会将其转换为字符串:默认转换需要Unicode文本数据,而不是Unicode文本数据二进制文件,并将更改换行符,依此类推.相反,可以考虑使用Stream.GetBuffer将其转换为byte []
If this is image data, then I wouldn''t convert it to a string: the default conversion expects unicode text data rather than binary, and will change newlines and so forth. Instead, consider converting it to a byte[] using Stream.GetBuffer
大家好,
我已将照片流转换为Windows Phone 7(C#.net)中的字符串.
使用的名称空间:
使用System.Windows.Controls;使用System.IO;使用System.Windows.Media.Imaging;
使用System.Windows.Media;
流到字符串:
hye all,
I have converted a photo stream to string as in Windows Phone 7 (C#.net)
namespaces used :
using System.Windows.Controls; using System.IO; using System.Windows.Media.Imaging;
using System.Windows.Media;
Stream to String :
BitmapImage bimg = new BitmapImage();
bimg.SetSource(photoStream); //photoStream is a stream containing data for a photo
byte[] bytearray = null;
using (MemoryStream ms = new MemoryStream())
{
WriteableBitmap wbitmp = new WriteableBitmap(bimg);
wbimg.SaveJpeg(ms, wbitmp.PixelWidth, wbitmp.PixelHeight, 0, 100);
ms.Seek(0, SeekOrigin.Begin);
bytearray = ms.GetBuffer();
}
string str = Convert.ToBase64String(bytearray);
要流式传输然后是图像的字符串:
String to Stream and then to Image :
byte[] data = Convert.FromBase64String(str);
Stream memStream = new MemoryStream(data);
WriteableBitmap wbimg = PictureDecoder.DecodeJpeg(memStream);
image1.Source = wbimg;
谢谢
thanks
这篇关于WP7串流并返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!