0
我在我的項目中添加了一些圖片(png),並且我在一個堆棧面板中加載了一個隨機圖像。我想要將該圖像保存到獨立存儲並從中加載它,但我如何保存一個隨機圖像?將隨機圖像保存並加載到獨立存儲
我在我的項目中添加了一些圖片(png),並且我在一個堆棧面板中加載了一個隨機圖像。我想要將該圖像保存到獨立存儲並從中加載它,但我如何保存一個隨機圖像?將隨機圖像保存並加載到獨立存儲
使用此代碼圖片字節流保存到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();
}