locked
get and save a file thumbnail

    Question

  • Hi everyone

    I have problem with getting file thumbnails and saving them !

    first at all I use this code to get video thumbnails :

    var v = await KnownFolders.VideosLibrary.GetFilesAsync();
    foreach (var file in v)
                {
                    var VF = await file.Properties.GetVideoPropertiesAsync();
                    if(VF.Duration.TotalSeconds != 0)
                    {
                        var thumb = await file.GetScaledImageAsThumbnailAsync(Windows.Storage.FileProperties.ThumbnailMode.SingleItem);
    //Other Codes to show Thumbnail
                    }
                }

    OK this works correctly but some videos have no thumbnail and they get a magnifier thumbnail ! is there any way to solve it or not ? or if it isn't anyway to solve how can I capture a snap shot or get a thumbnail view of for example second 10 of a video and then save it .

    also I have to say I tried  this code to save thumbnails I get from above code but the saved file seems an empty file . every time I try to load these files it return nothing !

    var thumb = await file.GetScaledImageAsThumbnailAsync(Windows.Storage.FileProperties.ThumbnailMode.SingleItem);
                        BitmapImage Img = new BitmapImage();
                        Img.SetSource(thumb);
                        ThumbImg.Source = Img;
                        var imageFile = await videoThumbFolder.CreateFileAsync(file.DisplayName + ".jpg", CreationCollisionOption.ReplaceExisting);
                                            Windows.Storage.Streams.Buffer MyBuffer = new Windows.Storage.Streams.Buffer(Convert.ToUInt32(thumb.Size));
                        IBuffer iBuf = await thumb.ReadAsync(MyBuffer, MyBuffer.Capacity, InputStreamOptions.None);
                        using (var strm = await imageFile.OpenAsync(FileAccessMode.ReadWrite))
                        {
                            await strm.WriteAsync(iBuf);
                        }

    my project is a Windows Phone 8.1 runtime project so trying to get thumbnail is not working as known issue in wp8.1 .
    so I used TagLib# portable to receive thumbnails using this code :

    try
                        {
                            var MusicFileGetP = await KnownFolders.MusicLibrary.GetFileAsync(file.Name);
                            var fileStream = await MusicFileGetP.OpenStreamForReadAsync();
                            var tagFile = File.Create(new StreamFileAbstraction(MusicFileGetP.Name, fileStream, fileStream));
                            var tags = tagFile.GetTag(TagTypes.Id3v2);
                            var img = tags.Pictures[0].Data.Data;
                            var imge = img.AsBuffer().AsStream().AsRandomAccessStream();
                            var thumb = imge;
                            btm.SetSource(thumb);
                        }
                        catch
                        {
                            btm.UriSource = new Uri("ms-appx:///Assets/appbar.music.png", UriKind.RelativeOrAbsolute);
                        }

    it works perfect too but I don't know how can I save these thumbnails in Local folder and restore them when I want .

    I'm really sort because of my long post and thanks everyone who helps me :)
    best regards

    Wednesday, April 01, 2015 5:14 PM

All replies

  • Hi ngame,

    Thanks for your description but if you can attach a repro we can test that might save our time, more communities are willing to help you debug the app.

    Try with videosView thumbnail mode to see if you can succeed.

    --James


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, April 02, 2015 9:23 AM
    Moderator
  • Thanks for your reply .

    I don't know what do you mean about repro :| if you want my full source code no matter I can provide it to you .

    Ok my new code is :

    #region Video Files Get Async var v = await KnownFolders.VideosLibrary.GetFilesAsync(); foreach (var file in v) { var VF = await file.Properties.GetVideoPropertiesAsync(); if(VF.Duration.TotalSeconds != 0) { try { var thumb = await file.GetScaledImageAsThumbnailAsync(Windows.Storage.FileProperties.ThumbnailMode.VideosView); BitmapImage Img = new BitmapImage(); Img.SetSource(thumb);

    //ThumbImg is a Image control in xaml ThumbImg.Source = Img; var imageFile = await videoThumbFolder.CreateFileAsync(file.DisplayName + ".jpg", CreationCollisionOption.ReplaceExisting); //var destinationFile = await ApplicationData.Current.TemporaryFolder.CreateFileAsync(thumb, CreationCollisionOption.GenerateUniqueName); Windows.Storage.Streams.Buffer MyBuffer = new Windows.Storage.Streams.Buffer(Convert.ToUInt32(thumb.Size)); IBuffer iBuf = await thumb.ReadAsync(MyBuffer, MyBuffer.Capacity, InputStreamOptions.None); using (var strm = await imageFile.OpenAsync(FileAccessMode.ReadWrite)) { await strm.WriteAsync(iBuf); } TextBlock1.Text = file.DisplayName; var now = await FileIO.ReadTextAsync(UserVideoFiles, UnicodeEncoding.Utf8); if (now != "") await FileIO.WriteTextAsync(UserVideoFiles, now + "\n" + file.Name + "|" + "", UnicodeEncoding.Utf8); else await FileIO.WriteTextAsync(UserVideoFiles, file.Name + "|" + "", UnicodeEncoding.Utf8); } catch (Exception) { } } } #endregion


    now this code ignore files without Thumbnail . with this code I couldn't able to show saved image in an image control and again it returns nothing

    Thursday, April 02, 2015 11:23 AM
  • Isn't there anyone to reply ? :|
    Saturday, April 04, 2015 1:26 PM
  • and Still waiting ....................
    Thursday, April 09, 2015 12:56 PM
  • Hi ngame,

    Sorry for the late response, busy with something else, Thanks for your understanding :)

    repro means the sample project that can demonstrator the issue, it could help us understand how it works and save time to copy/paste code.

    I still want to you share me the sample project, because some part of your code is still missing, for instance some variable declaration.

    --James


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.



    Tuesday, April 14, 2015 9:14 AM
    Moderator
  • Let me try to answer part of your questions:

    -> OK this works correctly but some videos have no thumbnail and they get a magnifier thumbnail ! is there any way to solve it or not ?

    What is the content of your video? By default, it should not be a simply magnifier thumbnail, instead it should be something like below with a small icon on the right bottom corner, if the video file does not have one, it will use system default instead of the magnifier, so the question here might be could you share a screenshot for the magnifier thumbnail and take a look if your system default setting like this.

    To save the thumbnail for a file, you could also ref: https://msdn.microsoft.com/en-us/magazine/jj651570.aspx

    --James


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, April 14, 2015 9:54 AM
    Moderator
  • Hi ngame,

    Sorry for the late response, busy with something else, Thanks for your understanding :)

    repro means the sample project that can demonstrator the issue, it could help us understand how it works and save time to copy/paste code.

    I still want to you share me the sample project, because some part of your code is still missing, for instance some variable declaration.

    --James


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click  to participate the survey.



    Here is a little Repro :

    http://wincare.ir/Repro.rar

    I don't know how to save Taglib thumbnail images and also what's going wrong in save or recovering video thumbnail images

    thank you


    Sunday, April 19, 2015 8:59 AM