zoukankan      html  css  js  c++  java
  • 请求网络数据(图片or音频)保存到指定路径下到独立存储中及从独立存储中读取指定路径的文件

            private void HttpTestGetImgCallback(HttpCallBackEventArgs e)
            {
                _progressbar.Visibility = Visibility.Collapsed;
                if (e.ErrorCode == (int)HttpStatusCode.OK)
                {
                    //请求返回
                    if (e.Result is byte[])
                    {
                        MemoryStream stream = new MemoryStream(e.Result as byte[]);
                        BitmapImage bmp = new BitmapImage();
                        bmp.SetSource(stream);
                        using (IsolatedStorageFile ISF = IsolatedStorageFile.GetUserStoreForApplication())
                        {
                            string dir = "Fengjing\\Icon\\10021\\143";//保存图片的目录
                            //声明图片保存路径变量
                            string imageSavePath = string.Empty;
                            if (!ISF.DirectoryExists(dir))//判断目录是否存在
                                ISF.CreateDirectory(dir);//创建目录
                            imageSavePath = dir + "\\" + "hello.png";//拼接图片保存路径
                            using (IsolatedStorageFileStream FileStream = ISF.OpenFile(imageSavePath, FileMode.OpenOrCreate, FileAccess.Write))
                            {
                                WriteableBitmap wb = new WriteableBitmap(bmp);
                                wb.SaveJpeg(FileStream, wb.PixelWidth, wb.PixelHeight, 0, 100);
                            }
                        }
                        _img.Source = bmp;
                        _txt.Visibility = Visibility.Collapsed;
                        _img.Visibility = Visibility.Visible;
                    }
                }
                else
                {
                    MessageBox.Show(GetErrorDesc(e.ErrorCode), "", MessageBoxButton.OK);
                }
            }
            public void ReadZImg(string zimgName)
            {
                using (IsolatedStorageFile storageFile = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    BitmapImage bi = new BitmapImage();
                    string fileDir = "Fengjing\\Icon\\10021\\143";
                    if (!storageFile.DirectoryExists(fileDir))//判断目录是否存在
                        storageFile.CreateDirectory(fileDir);//创建目录
                    string filePath = fileDir + "\\" + zimgName;
                    if (storageFile.FileExists(filePath))
                    {
                        using (IsolatedStorageFileStream fileStream = storageFile.OpenFile(filePath, FileMode.Open, FileAccess.Read))
                        {
                            bi.SetSource(fileStream);
                            _img.Source = bi;
                           
                        }
                    }
                    
                }
            }

  • 相关阅读:
    poj 1523 SPF (无向图 的 割点)
    codeforces Walking in the Rain (dp 水题 线性 dp)
    GaleShapley算法
    hdu 1087 Super Jumping! Jumping! Jumping! (最大 上升子序列 线性 dp)
    poj 3694 Network (无向图的 割边 lca )
    codeforces To Add or Not to Add (排序 + 优化)
    hdu 3996 Gold Mine ( 最大权闭合图 )
    转:WINFORM多线程编程
    C#串口serialPort操作
    用C# 根据 JSC100 V5.0读写器通讯协议 编写读卡器API
  • 原文地址:https://www.cnblogs.com/androllen/p/2772128.html
Copyright © 2011-2022 走看看