我在我的项目中添加了一些图片(png),并在 stackpanel 加载了一个随机图像。我想将该图像保存到独立存储并从中加载,但是我如何保存随机图像???
问问题
276 次
1 回答
0
使用此代码将图像字节流保存到 IS:
using (IsolatedStorageFileStream fileStream = new IsolatedStorageFileStream(tempJPEG, FileMode.Create, myIsolatedStorage))
{
using (BinaryWriter writer = new BinaryWriter(fileStream))
{
Stream resourceStream = new MemoryStream(imageData); //Byte[] imageData
long length = resourceStream.Length;
byte[] buffer = new byte[32];
int readCount = 0;
using (resourceStream)
{
resourceStream.Seek(0, SeekOrigin.Begin);
// Read file in chunks in order to reduce memory consumption and increase performance
while (readCount < length)
{
int actual = resourceStream.Read(buffer, 0, buffer.Length);
readCount += actual;
writer.Write(buffer, 0, actual);
}
}
}
fileStream.Close();
}
于 2012-10-29T07:58:03.257 回答