GetThumbnailAsync() 개인적인 메소드

private GetThumbnailAsync ( [ mode ) : IAsyncOperation
mode [
리턴 IAsyncOperation
		private async Task<StorageItemThumbnail> GetThumbnailForFile(StorageFile file)
		{
			try
			{
				return await file.GetThumbnailAsync(ThumbnailMode.ListView, 120);
			}
			catch
			{
			}

			var assetsFolder = await Package.Current.InstalledLocation.GetFolderAsync("Assets");
			StorageFile iconFile = null;
			try
			{
				iconFile = await assetsFolder.GetFileAsync(string.Format("{0}-icon.png", file.FileType.Trim('.')));
			}
			catch
			{
			}

			if (iconFile == null)
			{
				iconFile = await assetsFolder.GetFileAsync("generic-icon.png");
			}

			return await iconFile.GetThumbnailAsync(ThumbnailMode.ListView, 120);
		}
예제 #2
0
        // Fetches all the data for the specified file
        public async static Task<FileItem> fromStorageFile(StorageFile f, CancellationToken ct)
        {
            FileItem item = new FileItem();
            item.Filename = f.DisplayName;
            
            // Block to make sure we only have one request outstanding
            await gettingFileProperties.WaitAsync();

            BasicProperties bp = null;
            try
            {
                bp = await f.GetBasicPropertiesAsync().AsTask(ct);
            }
            catch (Exception) { }
            finally
            {
                gettingFileProperties.Release();
            }

            ct.ThrowIfCancellationRequested();

            item.Size = (int)bp.Size;
            item.Key = f.FolderRelativeId;

            StorageItemThumbnail thumb = await f.GetThumbnailAsync(ThumbnailMode.SingleItem).AsTask(ct);
            ct.ThrowIfCancellationRequested();
            BitmapImage img = new BitmapImage();
            await img.SetSourceAsync(thumb).AsTask(ct);

            item.ImageData = img;
            return item;
        }
예제 #3
0
 private async void Button_Click(object sender, RoutedEventArgs e)
 {
     FolderPicker fp = new FolderPicker();
     fp.FileTypeFilter.Add("*");
     fp.SuggestedStartLocation = PickerLocationId.Desktop;
     fp.ViewMode = PickerViewMode.Thumbnail;
     var files = await fp.PickSingleFolderAsync();
     iol = await files.GetFilesAsync();
    //IReadOnlyList<StorageFolder> file = iol
     Myobj myobj = new Myobj();
     ObservableCollection<Myobj> datasource = new ObservableCollection<Myobj>();
    //Windows.Storage.Streams.IRandomAccessStream iras = await sf.OpenAsync(FileAccessMode.Read);
    sf = iol[0];
    //IReadOnlyList<IStorageFile> file = ;
    foreach (StorageFile a in iol)
    {
        myobj.Name = sf.DisplayName.ToString();
        //gw.DisplayMemberPath = "Name";
        var tn = await sf.GetThumbnailAsync(Windows.Storage.FileProperties.ThumbnailMode.PicturesView);
        BitmapImage bi = new BitmapImage();
        bi.SetSource(tn);
        myobj.Thumbnail = bi;
        datasource.Add(myobj);
    }
        this.gw.ItemsSource = datasource;
      //  gw.DisplayMemberPath = "data";
        
    
 }
예제 #4
0
        private async Task ThumbnailPhoto(ExplorerItem item, StorageFile sf, bool file = false)
        {
            if (item == null && item.Image != null) return;

            StorageItemThumbnail fileThumbnail = await sf.GetThumbnailAsync(ThumbnailMode.SingleItem, 250);
            BitmapImage bitmapImage = new BitmapImage();
            bitmapImage.SetSource(fileThumbnail);
            if (file == false)
                item.Image = bitmapImage;
            else
                item.Image = bitmapImage;
        }
        public ReportPhoto(StorageFile file)
        {
            FilePath = file.Path;

            StorageItemThumbnail thumbnail = file.GetThumbnailAsync(ThumbnailMode.ListView).AsTask().Result;
            BitmapImage thumbnailImage = new BitmapImage();
            var ignore = thumbnailImage.SetSourceAsync(thumbnail);
            ThumbnailSource = thumbnailImage;

            StorageItemThumbnail imageAsThumbnail = file.GetScaledImageAsThumbnailAsync(ThumbnailMode.SingleItem).AsTask().Result;
            WriteableBitmap bitmap = new WriteableBitmap((int)imageAsThumbnail.OriginalWidth, (int)imageAsThumbnail.OriginalHeight);
            ignore = bitmap.SetSourceAsync(imageAsThumbnail);
            Bitmap = bitmap;
        }
예제 #6
0
        public async Task<StorageItemThumbnail> GetThumbnail(StorageFile file)
        {
            StorageItemThumbnail thumb = null;

            try
            {
                thumb = await file.GetThumbnailAsync(ThumbnailMode.VideosView);
            }
            catch (Exception ex)
            {
                LogHelper.Log("Error getting thumbnail: ");
                LogHelper.Log(ex);
            }
            return thumb;
        }
예제 #7
0
        private async void fopen_ClickAsync(object sender, RoutedEventArgs e)
        {
            var picker = new Windows.Storage.Pickers.FileOpenPicker();

            picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;
            picker.SuggestedStartLocation =
                Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;
            picker.FileTypeFilter.Add(".jpg");
            picker.FileTypeFilter.Add(".jpeg");
            picker.FileTypeFilter.Add(".png");

            Windows.Storage.StorageFile f = await picker.PickSingleFileAsync();

            if (f != null)
            {
                StorageItemThumbnail thumbnail = await f.GetThumbnailAsync(ThumbnailMode.PicturesView,
                                                                           200, ThumbnailOptions.UseCurrentScale);

                BitmapImage bmpImage = new BitmapImage();
                bmpImage.SetSource(thumbnail);
                img1.Source = bmpImage;
            }
        }
 private async Task setAlbumProfileImage(DataModel.LifeMapStructure lifeMap, StorageFile file)
 {
     StorageItemThumbnail fileThumbnail = await file.GetThumbnailAsync(ThumbnailMode.SingleItem, 700);
     BitmapImage bitmapImage = new BitmapImage();
     bitmapImage.SetSource(fileThumbnail);
     lifeMap.Image = bitmapImage;
 }
예제 #9
0
        public static async Task<BitmapImage> GetThumbnailFromStorageFile(StorageFile file)
        {
            ThumbnailMode thumbnailMode = ThumbnailMode.ListView;
            ThumbnailOptions thumbnailOptions = ThumbnailOptions.UseCurrentScale;

            BitmapImage bitmapThumbnail = new BitmapImage();
            StorageItemThumbnail thumbnail = await file.GetThumbnailAsync(thumbnailMode, ThumbnailSize, thumbnailOptions);
            if (thumbnail != null)
            {
                bitmapThumbnail.SetSource(thumbnail);
                return bitmapThumbnail;
            }
            else
            {
                return null;
            }
        }
        public async void albumart(StorageFile fil)
        {
            using (StorageItemThumbnail storageItemThumbnail = await fil.GetThumbnailAsync(ThumbnailMode.SingleItem, 200, ThumbnailOptions.ResizeThumbnail))

            using (IInputStream inputStreamAt = storageItemThumbnail.GetInputStreamAt(0))
            using (var dataReader = new DataReader(inputStreamAt))
            {
                uint u = await dataReader.LoadAsync((uint)storageItemThumbnail.Size);
                IBuffer readBuffer = dataReader.ReadBuffer(u);

                var tempFolder = ApplicationData.Current.RoamingFolder;
                try
                {
                    var imageFile = await tempFolder.CreateFileAsync(fil.DisplayName + ".png", CreationCollisionOption.OpenIfExists);

                    using (IRandomAccessStream randomAccessStream = await imageFile.OpenAsync(FileAccessMode.ReadWrite))
                    using (IOutputStream outputStreamAt = randomAccessStream.GetOutputStreamAt(0))
                    {
                        await outputStreamAt.WriteAsync(readBuffer);
                        await outputStreamAt.FlushAsync();
                    }
                }
                catch
                {

                    //  ErrorCorrecting("013");

                }

            }
        }
 private static async Task<bool> setAlbumProfileImage(DataModel.AlbumDataStructure item, StorageFile file)
 {
     try
     {
         StorageItemThumbnail fileThumbnail = await file.GetThumbnailAsync(ThumbnailMode.SingleItem, 400);
         BitmapImage bitmapImage = new BitmapImage();
         bitmapImage.SetSource(fileThumbnail);
         item.ImagePath = bitmapImage;
         return true;
     }
     catch
     {
         return false;
     }
 }
        private async void fillBackgroundImage(LifeMapStructure lifeMap, StorageFile storageFile)
        {
            Utils.Constants.StartLoadingAnimation(MainGrid);
            if (lifeMap.ImagePath != "")
            {
                try
                {
                    StorageFile sf = await Windows.Storage.StorageFile.GetFileFromPathAsync(storageFile.Path);
                    StorageItemThumbnail fileThumbnail = await storageFile.GetThumbnailAsync(ThumbnailMode.SingleItem, 800);
                    BitmapImage bitmapImage = new BitmapImage();
                    bitmapImage.SetSource(fileThumbnail);
                    lifeMap.Image = bitmapImage;
                    await Utils.FilesSaver<LifeMapStructure>.SaveData(Data.LifeMapMgr.LifeMaps, Constants.NamingListLifeMaps);
                    Helper.CreateToastNotifications(Constants.ResourceLoader.GetString("UpdatedLiftMapBackground"));
                }
                catch
                {
					lifeMap.ImagePath = "";
                    Utils.Constants.ShowWarningDialog(Constants.ResourceLoader.GetString("2cannotreadfile") + " : " + storageFile.Path + "\n\r" +
                                                      Constants.ResourceLoader.GetString("2possiblereasondocumentlibararycannotaccess"));
                }
            }
            else
            {
                await fillBackgroundImageNonLocal(lifeMap, storageFile);
            }
            Utils.Constants.StopLoadingAnimation(MainGrid);
        }
예제 #13
0
        public async static Task <List <IOElement> > ParseWindowsFiles(string rawList, string path)
        {
            List <IOElement> files = new List <IOElement>();

            foreach (string item in rawList.Trim().Split('\n'))
            {
                IOElement newElement = new IOElement();

                string trimmedItem = item.Trim();

                int timeEnding = 0;

                for (int i = 8; i < trimmedItem.Length; i++)
                {
                    if (trimmedItem[i] != ' ')
                    {
                        for (int j = i; j < trimmedItem.Length; j++)
                        {
                            if (trimmedItem[i] == ' ')
                            {
                                timeEnding = j;
                                break;
                            }
                        }
                    }
                }

                newElement.LastEdit = trimmedItem.Substring(0, timeEnding).Trim();
                while (newElement.LastEdit.Contains("  "))
                {
                    newElement.LastEdit = newElement.LastEdit.Replace("  ", " ");
                }

                int typeBeginning = 0;
                int typeEnding    = 0;

                for (int i = 17; i < trimmedItem.Length; i++)
                {
                    if (trimmedItem[i] != ' ')
                    {
                        typeBeginning = i;
                        break;
                    }
                }

                for (int i = typeBeginning; i < trimmedItem.Length; i++)
                {
                    if (trimmedItem[i] == ' ')
                    {
                        typeEnding = i;
                        break;
                    }
                }

                newElement.FileType = trimmedItem.Substring(typeBeginning, typeEnding - typeBeginning).Replace("<DIR>", "Directory");

                newElement.IsFile = newElement.FileType != "Directory";

                int nameBeginning = 0;
                for (int i = typeEnding + 1; i < trimmedItem.Length; i++)
                {
                    if (trimmedItem[i] != ' ')
                    {
                        nameBeginning = i;
                        break;
                    }
                }

                newElement.Name = trimmedItem.Substring(nameBeginning, trimmedItem.Length - nameBeginning);

                newElement.Path = path;

                //skip those entries
                if (newElement.Name == "." || newElement.Name == "..")
                {
                    continue;
                }

                ulong size = 0;
                ulong.TryParse(newElement.FileType, out size);

                newElement.Size = size;

                if (size != 0)
                {
                    newElement.FileType = newElement.Name.Split('.').Last();
                }

                if (newElement.IsFile)
                {
                    if (newElement.Name.Contains('.'))
                    {
                        newElement.FileType = newElement.Name.Substring(newElement.Name.LastIndexOf('.'));
                    }
                    else
                    {
                        newElement.FileType = newElement.Name;
                    }
                }

                //set the icon
                string filename = "_tmp_ext" + newElement.Name.Split('.').Last();
                Windows.Storage.StorageFile iconHelperFile = await ApplicationData.Current.TemporaryFolder.CreateFileAsync(filename, CreationCollisionOption.OpenIfExists);

                Windows.Storage.FileProperties.StorageItemThumbnail iconHelperThumbnail = await iconHelperFile.GetThumbnailAsync(Windows.Storage.FileProperties.ThumbnailMode.SingleItem,
                                                                                                                                 16, Windows.Storage.FileProperties.ThumbnailOptions.ResizeThumbnail);

                if (iconHelperThumbnail != null)
                {
                    BitmapImage bitmapImage = new BitmapImage();
                    bitmapImage.SetSource(iconHelperThumbnail.CloneStream());
                    newElement.Icon = bitmapImage;
                }

                files.Add(newElement);
            }

            return(files);
        }
예제 #14
0
        public static async Task <List <IOElement> > ParseLinuxFiles(string rawList, string path)
        {
            List <IOElement> files = new List <IOElement>();

            foreach (string item in rawList.Trim().Split('\n'))
            {
                IOElement newElement = new IOElement();

                string trimmedItem = item.Trim();

                string tmp = trimmedItem.Substring(0, trimmedItem.IndexOf(' ')).Trim();

                trimmedItem = trimmedItem.Remove(0, trimmedItem.IndexOf(' '));

                newElement.IsFile = tmp.StartsWith("d") ? false : true;

                int ownerNumber  = 0;
                int groupNumber  = 0;
                int publicNumber = 0;

                if (tmp[1] == 'r')
                {
                    ownerNumber += 4;
                }
                if (tmp[2] == 'w')
                {
                    ownerNumber += 2;
                }
                if (tmp[3] == 'x')
                {
                    ownerNumber += 1;
                }

                if (tmp[4] == 'r')
                {
                    groupNumber += 4;
                }
                if (tmp[5] == 'w')
                {
                    groupNumber += 2;
                }
                if (tmp[6] == 'x')
                {
                    groupNumber += 1;
                }

                if (tmp[7] == 'r')
                {
                    publicNumber += 4;
                }
                if (tmp[8] == 'w')
                {
                    publicNumber += 2;
                }
                if (tmp[9] == 'x')
                {
                    publicNumber += 1;
                }

                newElement.Rigths       = ownerNumber * 100 + groupNumber * 10 + publicNumber;
                newElement.RigthsString = newElement.Rigths.ToString();

                trimmedItem = trimmedItem.Trim();

                string trash = trimmedItem.Substring(0, trimmedItem.IndexOf(' '));
                trimmedItem      = trimmedItem.Remove(0, trimmedItem.IndexOf(' ')).Trim();
                newElement.Owner = trimmedItem.Substring(0, trimmedItem.IndexOf(' '));

                trimmedItem      = trimmedItem.Remove(0, trimmedItem.IndexOf(' ')).Trim();
                newElement.Group = trimmedItem.Substring(0, trimmedItem.IndexOf(' '));

                trimmedItem     = trimmedItem.Remove(0, trimmedItem.IndexOf(' ')).Trim();
                newElement.Size = ulong.Parse(trimmedItem.Substring(0, trimmedItem.IndexOf(' ')));

                trimmedItem         = trimmedItem.Remove(0, trimmedItem.IndexOf(' ')).Trim();
                newElement.LastEdit = trimmedItem.Substring(0, trimmedItem.IndexOf(' '));

                trimmedItem          = trimmedItem.Remove(0, trimmedItem.IndexOf(' ')).Trim();
                newElement.LastEdit += "." + trimmedItem.Substring(0, trimmedItem.IndexOf(' '));

                trimmedItem          = trimmedItem.Remove(0, trimmedItem.IndexOf(' ')).Trim();
                newElement.LastEdit += "." + trimmedItem.Substring(0, trimmedItem.IndexOf(' '));

                trimmedItem = trimmedItem.Remove(0, trimmedItem.IndexOf(' ')).Trim();

                newElement.Name = trimmedItem;

                newElement.Path = path;

                //skip those entries
                if (newElement.Name == "." || newElement.Name == "..")
                {
                    continue;
                }

                if (newElement.IsFile == false)
                {
                    newElement.FileType = "Directory";
                }
                else
                {
                    if (newElement.Name.Contains("."))
                    {
                        newElement.FileType = newElement.Name.Substring(newElement.Name.LastIndexOf('.'));
                    }
                    else
                    {
                        newElement.FileType = newElement.Name;
                    }
                }

                //set the icon
                if (newElement.IsFile)
                {
                    string filename = "_tmp_ext" + "." + newElement.Name.Split('.').Last();
                    Windows.Storage.StorageFile iconHelperFile = await ApplicationData.Current.TemporaryFolder.CreateFileAsync(filename, CreationCollisionOption.OpenIfExists);

                    Windows.Storage.FileProperties.StorageItemThumbnail iconHelperThumbnail = await iconHelperFile.GetThumbnailAsync(Windows.Storage.FileProperties.ThumbnailMode.SingleItem,
                                                                                                                                     64, Windows.Storage.FileProperties.ThumbnailOptions.ResizeThumbnail);

                    if (iconHelperThumbnail != null)
                    {
                        try
                        {
                            await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                            {
                                BitmapImage bitmapImage = new BitmapImage();
                                bitmapImage.SetSource(iconHelperThumbnail.CloneStream());
                                newElement.Icon = bitmapImage;
                            });
                        }
                        catch (Exception ex) { }
                    }
                }

                files.Add(newElement);
            }

            return(files);
        }
예제 #15
0
 public async void AddThumbnail(StorageFile file, VideoDataItem item) {
     StorageItemThumbnail thumb = await file.GetThumbnailAsync(ThumbnailMode.VideosView);
     if(thumb != null) {
         BitmapImage img = new BitmapImage();
         await img.SetSourceAsync(thumb);
         item.Image = img; } }
예제 #16
0
        public async static Task FillFileProperties(IFileProperties fileProps, StorageFile file, StorageFolder topFolder, string fileSubPath, BasicProperties basicProps)
        {
            try
            {
                fileProps.FileName = file.Name;
                fileProps.AbsolutePath = file.Path;

                fileProps.SelectedFolder = Util.FolderPath(topFolder);

                if (!string.IsNullOrEmpty(fileSubPath))
                    fileProps.ContainingFolder = fileSubPath;
                else
                    fileProps.ContainingFolder = ""; //fileProps.HideContainingFolder();

                string ftype = GetFileTypeText(file, false);
                if (!string.IsNullOrEmpty(ftype))
                    fileProps.FileType = ftype;
                else
                    fileProps.HideFileType();

                if (basicProps != null)
                    fileProps.FileSize = Util.SizeToString(basicProps.Size, "B");
                else
                    fileProps.HideFileSize();

                if (!string.IsNullOrEmpty(file.Provider.DisplayName))
                {
                    string flocation = file.Provider.DisplayName;
                    if (!string.IsNullOrEmpty(file.Provider.Id) && file.Provider.DisplayName.IndexOf(file.Provider.Id, StringComparison.OrdinalIgnoreCase) <= -1)
                        flocation += " (" + file.Provider.Id.Substring(0, 1).ToUpper() + file.Provider.Id.Substring(1) + ") ";
                    fileProps.FileLocation = flocation;
                }
                else if (!string.IsNullOrEmpty(file.Provider.Id))
                    fileProps.FileLocation = file.Provider.Id;
                else
                    fileProps.HideFileLocation();

                StorageItemThumbnail thumbnail = await file.GetThumbnailAsync(ThumbnailMode.DocumentsView, 260, ThumbnailOptions.None);
                Image image = Util.GetImage(thumbnail);
                if (image != null)
                    fileProps.FileImage = image.Source;
            }
            catch (Exception ex) { Debug.WriteLine(ex.ToString()); }
        }
        private static async Task affectBitmapImageToNewDisplayablePhotoObject(StorageFile file, PhotoDataStructure pds)
        {
			try
			{
				if(file == null || pds == null) return;
				StorageItemThumbnail fileThumbnail = await file.GetThumbnailAsync(ThumbnailMode.SingleItem, 600);
				BitmapImage bitmapImage = new BitmapImage();
				bitmapImage.SetSource(fileThumbnail);
				pds.Image = bitmapImage;
			}
			catch(Exception exp)
			{
				throw exp;
			}
        }
 private static async Task affectBitmapImageToNewDisplayablePhotoObject(StorageFile file, VideoDataStructure pds)
 {
     StorageItemThumbnail fileThumbnail = await file.GetThumbnailAsync(ThumbnailMode.SingleItem, 900);
     BitmapImage bitmapImage = new BitmapImage();
     bitmapImage.SetSource(fileThumbnail);
     pds.Image = bitmapImage;
 }
 private async Task<StorageItemThumbnail> GetThumbnail(StorageFile file)
 {
     return await file.GetThumbnailAsync(ThumbnailMode.PicturesView, 230);
 }