Example #1
0
 public async Task ReadPpmFile(StorageFile file)
 {
     using (FileRandomAccessStream stream = (FileRandomAccessStream)await file.OpenAsync(FileAccessMode.Read))
     {
         using (BinaryReader reader = new BinaryReader(stream.AsStream()))
         {
             var format = reader.ReadBytes(2);
             Format = ((char)format[0]).ToString() + ((char)format[1]);
             if (Format.Equals("P3"))
             {
                 ReadTextImage1(stream.AsStream());
             }
             else if (Format.Equals("P6"))
             {
                 ReadBinaryImage(reader);
             }
         }
     }
 }
Example #2
0
        internal SqoWinRTFile(String filePath, bool readOnly)
        {
            this.folderPath = filePath.Remove(filePath.LastIndexOf('\\'));
            this.fileName   = filePath.Substring(filePath.LastIndexOf('\\') + 1);
            isClosed        = false;
            storageFolder   = StorageFolder.GetFolderFromPathAsync(folderPath).AsTask().Result;
            this.file       = storageFolder.CreateFileAsync(this.fileName, CreationCollisionOption.OpenIfExists).AsTask().Result;
            this.fileStream = (FileRandomAccessStream)file.OpenAsync(FileAccessMode.ReadWrite).AsTask().Result;
            this.stream     = fileStream.AsStream();

            //this.streamReader = fileStream.AsStreamForRead();
        }
Example #3
0
        public void Flush()
        {
            try
            {
                if (fileStream != null && !this.IsClosed && isModified)
                {
                    stream.Flush();
                    byte[] bytes = stream.ToArray();
                    fileStream.Seek(0);
                    var streamTemp = fileStream.AsStream();

                    streamTemp.Write(bytes, 0, bytes.Length);
                    streamTemp.Flush();

                    fileStream.FlushAsync().AsTask().Wait();
                    isModified = false;
                }
            }
            catch (FileNotFoundException ex)//did not found a better way to check if file exists
            {
            }
        }
Example #4
0
        internal SqoWinRTMemoryFile(String filePath, bool readOnly)
        {
            this.folderPath   = filePath.Remove(filePath.LastIndexOf('\\'));
            this.fileName     = filePath.Substring(filePath.LastIndexOf('\\') + 1);
            isClosed          = false;
            storageFolder     = StorageFolder.GetFolderFromPathAsync(folderPath).AsTask().Result;
            this.physicalFile = storageFolder.CreateFileAsync(this.fileName, CreationCollisionOption.OpenIfExists).AsTask().Result;
            this.fileStream   = (FileRandomAccessStream)physicalFile.OpenAsync(FileAccessMode.ReadWrite).AsTask().Result;
            stream            = new MemoryStream();
            byte[] fullFile   = new byte[fileStream.Size];
            var    streamTemp = fileStream.AsStream();

            streamTemp.Read(fullFile, 0, fullFile.Length);

            stream.Write(fullFile, 0, fullFile.Length);
        }
Example #5
0
        public async Task <BitmapImage> LoadImage(StorageFile file)
        {
            BitmapImage bitmapImage = new BitmapImage();

            using (FileRandomAccessStream fras = (FileRandomAccessStream)await file.OpenAsync(FileAccessMode.Read))
            {
                //把圖像複製到記憶體中,脫離對StorageFile的依賴
                Stream       stream    = fras.AsStream();
                MemoryStream memStream = new MemoryStream();
                await stream.CopyToAsync(memStream);

                memStream.Position = 0;
                bitmapImage.SetSource(memStream.AsRandomAccessStream());
            }

            return(bitmapImage);
        }
Example #6
0
        /// <summary>
        /// 從檔案獲得BitmapImage
        /// </summary>
        /// <param name="file">已存在的StorageFile</param>
        private async Task <BitmapImage> GetBitmapImage(StorageFile file)
        {
            BitmapImage bmp = new BitmapImage();

            using (FileRandomAccessStream fras = (FileRandomAccessStream)await file.OpenAsync(FileAccessMode.Read))
            {
                //把圖像複製到記憶體中,脫離對StorageFile的依賴
                Stream       stream    = fras.AsStream();
                MemoryStream memStream = new MemoryStream();
                await stream.CopyToAsync(memStream);

                stream.Dispose();
                memStream.Position = 0;
                bmp.SetSource(memStream.AsRandomAccessStream());
            }

            return(bmp);
        }