当前位置:编程学习 > wap >>

求助!读取IsolatedStorageFile中的图片显示报错

我先用下面的代码将一张图片保存到独立存储中,
   using (IsolatedStorageFileStream isoStream = isofile.OpenFile(path ,
                                            FileMode.Create, FileAccess.Write))
                    {                      
                        byte[] bytes = new byte[imageSource.Length];
                        imageSource.Read(bytes, 0, (int)imageSource.Length);                       
                        isoStream.Write(bytes, 0, bytes.Length);
                        // imageSource.CopyTo(isoStream);   这样isoStream的Length仍然是0
                        isoStream.Flush();
                       
                    }


然后再读取:
 using (IsolatedStorageFileStream isoStream = isofile.OpenFile(path, FileMode.Open, FileAccess.Read))
                {
                   
                    BitmapImage bmp = new BitmapImage();
                    bmp.SetSource(isoStream);           // isoStream长度不为0,说明有图片吧?
                    return bmp;
                }


但是在执行到bmp.SetSource时会抛出异常:The component cannot be found.
请问这是什么原因呢?另外如果要读取图片并显示的话还能怎么做呢?谢了! --------------------编程问答-------------------- isoStream.Seek(0);
bmp.SetSource(isoStream);   

试试         --------------------编程问答--------------------
引用 1 楼 NianHui 的回复:
isoStream.Seek(0);
bmp.SetSource(isoStream);   

试试        
--------------------编程问答--------------------
引用 2 楼 blogtjf 的回复:
Quote: 引用 1 楼 NianHui 的回复:

isoStream.Seek(0);
bmp.SetSource(isoStream);   

试试        

笑毛?
补充:移动开发 ,  Windows Phone
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,