问题描述
我必须将一个writablebitmap写入一个文件,然后从同一个文件加载writablebitmap。
我的图像是正方形(ss x ss resolution)
此代码将writablebitmap写入文件
StreamWriter writeFile = new StreamWriter(new IsolatedStorageFileStream(" tmp / tmp。 img",FileMode.Create,myStore));
BinaryWriter bw = new BinaryWriter(writeFile.BaseStream);
for(int i = 0; i< wb.Pixels.Length; i ++)
{
bw.Write(wb.Pixels [i]);
}
writeFile.Flush();
writeFile.Close();
writeFile.Dispose();
此代码读取相同的文件
StreamReader sr = new StreamReader(new IsolatedStorageFileStream(" tmp / tmp.img",FileMode.Open,myStore));
wb.Invalidate();
BinaryReader br = new BinaryReader(sr.BaseStream);
WriteableBitmap wb = new WriteableBitmap((int)Math.Sqrt(sr.BaseStream.Length / sizeof(int)),(int)Math.Sqrt(sr.BaseStream.Length / sizeof(int)));
int k = 0;
sr.BaseStream.Seek(0,SeekOrigin.Begin);
while(sr.BaseStream.Position< sr.BaseStream.Length)
{
wb.Pixels [k] = br.ReadInt32();
k ++;
}
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; sr.Close();
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; sr.Dispose();
但阅读速度非常慢。
如何提高代码的速度?
谢谢
I have to write a writablebitmap to a file and then load the writablebitmap from the same file.
My image is square (ss x ss resolution)
This code write the writablebitmap to a file
StreamWriter writeFile = new StreamWriter(new IsolatedStorageFileStream("tmp/tmp.img", FileMode.Create, myStore)); BinaryWriter bw = new BinaryWriter(writeFile.BaseStream); for (int i = 0; i < wb.Pixels.Length; i++) { bw.Write(wb.Pixels[i]); } writeFile.Flush(); writeFile.Close(); writeFile.Dispose();
And this code read the same file
StreamReader sr = new StreamReader(new IsolatedStorageFileStream("tmp/tmp.img", FileMode.Open, myStore)); BinaryReader br = new BinaryReader(sr.BaseStream); WriteableBitmap wb = new WriteableBitmap((int)Math.Sqrt(sr.BaseStream.Length/sizeof(int)), (int)Math.Sqrt(sr.BaseStream.Length/sizeof(int))); int k=0; sr.BaseStream.Seek(0, SeekOrigin.Begin); while(sr.BaseStream.Position<sr.BaseStream.Length) { wb.Pixels[k] = br.ReadInt32(); k++; }
wb.Invalidate();
sr.Close();
sr.Dispose();
But to read is very very slow.
How can I improve the speed of my code?
Thanks
这篇关于保存并加载writablebitmap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!