public void GetImage()
        {
            MediaSource mediaSource = MediaSource.GetAvailableMediaSources().First(source => source.MediaSourceType == MediaSourceType.LocalDevice);

            using (MediaLibrary mediaLibrary = new MediaLibrary(mediaSource))
            {
                PictureAlbum      cameraRollAlbum = mediaLibrary.RootPictureAlbum.Albums.First((album) => album.Name == "Camera Roll"); //Get albulm Cameraroll
                PictureCollection pictures        = cameraRollAlbum.Pictures;
                //MessageBox.Show(pictures.Count().ToString());
                try
                {
                    if (pictures != null)
                    {
                        foreach (var item in pictures)
                        {
                            //binding to listbox
                            BitmapImage bitImage = new BitmapImage();
                            bitImage.SetSource(item.GetThumbnail());
                            MediaImage mediaImage = new MediaImage();
                            mediaImage.ImageFile = bitImage;
                            listImage.Add(mediaImage);
                        }
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show("Camera roll null");
                }
            }
        }
Example #2
0
 static InMemoryDataStore()
 {
     for (var i = 1; i < 6; i++)
     {
         var newAlbum = new PictureAlbum
         {
             Id          = Guid.NewGuid(),
             Name        = "Album " + i,
             Description = "This is Album number " + i,
             Tags        = new List <string> {
                 "album", i.ToString()
             },
             Pictures = new List <Picture>()
         };
         var numberOfPictures = new Random(25).Next(15) + 1;
         for (var j = 1; j < numberOfPictures; j++)
         {
             newAlbum.Pictures.Add(new Picture
             {
                 Id            = Guid.NewGuid(),
                 Height        = 100 * j,
                 Width         = 150 * j,
                 Url           = RandomImageUrl,
                 ParentAlbumId = newAlbum.Id
             }
                                   );
         }
         PictureAlbums.Add(newAlbum);
     }
 }
Example #3
0
        public Stream ReadPhotoAsStream(Uri location)
        {
            Stream result = null;

            if (location != null)
            {
                using (MediaLibrary ml = new MediaLibrary())
                {
                    PictureAlbum cameraRoll = ml.RootPictureAlbum.Albums
                                              .Where((a) => String.Equals(a.Name, "Camera Roll"))
                                              .FirstOrDefault();
                    if (cameraRoll != null)
                    {
                        Picture match = cameraRoll.Pictures
                                        .Where((p) => String.Equals(p.Name, location.ToString()))
                                        .FirstOrDefault();
                        if (match != null)
                        {
                            result = match.GetImage();
                        }
                    }
                }
            }
            return(result);
        }
Example #4
0
 private void InitializeImageSizes()
 {
     Stopwatch.StartNew();
     this._imageSizes.Clear();
     using (MediaLibrary mediaLibrary = new MediaLibrary())
     {
         // ISSUE: method pointer
         PictureAlbum pictureAlbum = ((IEnumerable <PictureAlbum>)mediaLibrary.RootPictureAlbum.Albums).FirstOrDefault <PictureAlbum>((Func <PictureAlbum, bool>)(a => a.Name == this._albumId));
         if ((pictureAlbum != null))
         {
             using (IEnumerator <Picture> enumerator = pictureAlbum.Pictures.GetEnumerator())
             {
                 while (((IEnumerator)enumerator).MoveNext())
                 {
                     Picture     current    = enumerator.Current;
                     List <Size> imageSizes = this._imageSizes;
                     Size        size1      = new Size();
                     // ISSUE: explicit reference operation
                     size1.Width = ((double)current.Width);
                     // ISSUE: explicit reference operation
                     size1.Height = ((double)current.Height);
                     Size size2 = size1;
                     imageSizes.Add(size2);
                     current.Dispose();
                 }
             }
             pictureAlbum.Dispose();
         }
         this._imageSizes.Reverse();
     }
 }
 public AlbumListItem(PictureAlbum album, SelectiveSyncViewModel parent)
 {
     AlbumName = album.Name;
     Album = album;
     Parent = parent;
     Thumb = new BitmapImage();
     Thumb.SetSource(album.Pictures.First().GetThumbnail());
 }
        private void ReportAlbumPictures(PictureAlbum pa, int iPic)
        {
            string sIndiciesToItem = "";
            string sFolderPath     = "";

            foreach (StackItem si in m_stck)
            {
                if (sIndiciesToItem.Length > 0)
                {
                    sIndiciesToItem += "|";
                }
                sIndiciesToItem += si.Index.ToString();

                if (sFolderPath.Length > 0)
                {
                    sFolderPath += "\\";
                }
                sFolderPath += si.pa.Name;
            }

            /*
             * if( sIndiciesToItem.Length > 0 ) sIndiciesToItem += "|";
             * sIndiciesToItem += m_iIdx.ToString();
             */
            if (sIndiciesToItem.Length > 0)
            {
                sIndiciesToItem += "|";
            }
            sIndiciesToItem += iPic.ToString();
            if (sFolderPath.Length > 0)
            {
                sFolderPath += "\\";
            }
            sFolderPath += pa.Name;

            Picture pic = pa.Pictures[iPic];

            RscMediaLibItemDesc it = new RscMediaLibItemDesc();

            it.bFolder = false;

            it.sIndiciesToItem = sIndiciesToItem;
            it.sFolderPath     = sFolderPath;

            it.sName = pic.Name;

            it.sDetails  = "";
            it.sDetails += sFolderPath;
            it.sDetails += "\r\n";
            it.sDetails += sIndiciesToItem;
            it.sDetails += "\r\n";
            it.sDetails += "DateTime: " + pic.Date.ToShortDateString() + " " + pic.Date.ToShortTimeString();
            it.sDetails += "\r\n";
            it.sDetails += "Dimenstion: " + pic.Width.ToString() + " x " + pic.Height.ToString();

            AddFile(it);
        }
Example #7
0
        public override Guid UpdatePictureAlbum(dynamic pictureAlbum)
        {
            var standardizedAlbum = new PictureAlbum();

            standardizedAlbum.Id          = pictureAlbum.Id;
            standardizedAlbum.Name        = pictureAlbum.Name;
            standardizedAlbum.Description = pictureAlbum.Description;
            return(base.UpdatePictureAlbum(standardizedAlbum));
        }
Example #8
0
        public async Task <IHttpActionResult> PostPictureAlbum(PictureAlbum pictureAlbum)
        {
            var addTask = new Task <Guid>(() => this.PictureAlbumsRepository.AddPictureAlbum(pictureAlbum));

            addTask.Start();
            var pictureAlbumId = await addTask;

            return(CreatedAtRoute("PictureAlbum", new { id = pictureAlbumId }, pictureAlbum));
        }
 private void ReSet()
 {
     m_media   = new MediaLibrary();
     m_stck    = new List <StackItem>();
     m_pa      = m_media.RootPictureAlbum;
     m_iIdx    = -1;
     m_paPic   = null;
     m_iIdxPic = -1;
 }
Example #10
0
        public async Task <IHttpActionResult> PutPictureAlbum(Guid pictureAlbumId, PictureAlbum pictureAlbum)
        {
            if (ModelState.IsValid && pictureAlbum != null)
            {
                pictureAlbum.Id = pictureAlbumId;
                var updateTask = new Task <Guid>(() => this.PictureAlbumsRepository.UpdatePictureAlbum(pictureAlbum));
                updateTask.Start();
                await updateTask;
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Example #11
0
        public override bool FolderExists(string path)
        {
            //MUST NOT!!!
            //if( path.IndexOf( '.' ) < 0 ) return false; //No exists for Albums...

            PictureAlbum pa = GetPictureAlbumObject(path);

            if (pa == null)
            {
                return(false);                         //Not found...
            }
            return(true);
        }
Example #12
0
 public async void Initialize(PictureAlbum album, CancellationToken token, bool fromLibrary = true)
 {
     if (fromLibrary)
     {
         IsSelectionEnabled = true;
         await LoadAlbumsFromMediaLibraryAsync(album, token);
     }
     else
     {
         IsSelectionEnabled = false;
         await LoadAlbumPhotosFromStoreAsync(album.Name, token);
     }
 }
Example #13
0
 public async void Initialize(PictureAlbum album, CancellationToken token, bool fromLibrary = true)
 {
     if (fromLibrary)
     {
         IsSelectionEnabled = true;
         await LoadAlbumsFromMediaLibraryAsync(album, token);
     }
     else
     {
         IsSelectionEnabled = false;
         await LoadAlbumPhotosFromStoreAsync(album.Name, token);
     }
 }
Example #14
0
        private void LoadFromMediaLibrary(List <IThumbnailedImage> tempCameraRoll)
        {
            PictureAlbum rootAblum = this.mediaLibrary.RootPictureAlbum;

            foreach (PictureAlbum album in rootAblum.Albums)
            {
                if (album.Name == AppResources.CameraRollAlbumName)
                {
                    foreach (Picture picture in album.Pictures)
                    {
                        tempCameraRoll.Add(new MediaLibraryThumbnailedImage(picture));
                    }
                }
            }
        }
        // Checks to see if the picture is uploaded, if not, creates a
        // AsyncHttpPostHelper instance to handle the upload. The callback method is
        // passed to this instance to notify the ServiceUploadHelper when to upload
        // the next picture.
        private void UploadPicture(PictureAlbum album, int index)
        {
            Picture picture = album.Pictures[index];

            if (photoDataModel.IsAlreadyUploaded(picture))
            {
                // Do nothing
            }
            else
            {
                // Initialise a AsyncHttpPostHelper to upload the picture.
                Uri requestUri = new Uri(AsyncHttpPostHelper.ConstantStrings.apiUri + HttpUtility.UrlEncode(strAccessToken));
                AsyncHttpPostHelper asyncHttpPostHelper = new AsyncHttpPostHelper(picture, requestUri);
                asyncHttpPostHelper.BeginSend(OnHttpPostCompleteDelegate);
            }
        }
        private void ReportAlbum(PictureAlbum pa)
        {
            string sIndiciesToItem = "";
            string sFolderPath     = "";

            foreach (StackItem si in m_stck)
            {
                if (sIndiciesToItem.Length > 0)
                {
                    sIndiciesToItem += "|";
                }
                sIndiciesToItem += si.Index.ToString();

                if (sFolderPath.Length > 0)
                {
                    sFolderPath += "\\";
                }
                sFolderPath += si.pa.Name;
            }

            /*
             * if( sFolderPath.Length > 0 ) sFolderPath += "\\";
             * sFolderPath += pa.Name;
             */

            RscMediaLibItemDesc it = new RscMediaLibItemDesc();

            it.bFolder = true;

            it.sIndiciesToItem = sIndiciesToItem;
            it.sFolderPath     = sFolderPath;

            it.sName = pa.Name;

            it.sDetails  = "";
            it.sDetails += sFolderPath;
            it.sDetails += "\r\n";
            it.sDetails += sIndiciesToItem;
            it.sDetails += "\r\n";
            it.sDetails += "Album count: " + pa.Albums.Count.ToString();
            it.sDetails += "\r\n";
            it.sDetails += "Picture count: " + pa.Pictures.Count.ToString();

            AddFile(it);
        }
        /*
         * private void btn_DoubleTap(object sender, System.Windows.Input.GestureEventArgs e)
         * {
         *      Button btn;
         *      btn = ((Button) sender);
         *      RscMediaLibItemDesc it;
         *      it = (RscMediaLibItemDesc) btn.Tag;
         *
         *      if( it.bFolder )
         *      {
         *              //m_path.Push( it.sFn );
         *
         *              //ListFiles();
         *      }
         *      else
         *      {
         *              //m_txtTitle.Text = "medlib:\\" + it.sFolderPath + "\\" + it.sName;
         *
         *              m_btnImage.Visibility = Rsc.Visible;
         *              m_btnImage.Tag = it.sIndiciesToItem;
         *              m_btnImage.Image.Source = LoadImage( it, false, 96, 160 );
         *      }
         * }
         */

        private ImageSource LoadImage(RscMediaLibItemDesc it, bool bThumbnail, int iCX, int iCY)
        {
            if (it.bFolder)
            {
                return(m_AppFrame.Theme.GetImage("Images/Ico001_Ressive.jpg"));
            }

            // //
            //

            PictureAlbum pa  = m_media.RootPictureAlbum;
            Picture      pic = null;

            string [] asInd = it.sIndiciesToItem.Split('|');
            int       iCnt  = asInd.Length;

            for (int i = 0; i < iCnt; i++)
            {
                if (i == iCnt - 1)
                {
                    pic = pa.Pictures[Int32.Parse(asInd[i])];
                }
                else
                {
                    pa = pa.Albums[Int32.Parse(asInd[i])];
                }
            }

            //
            // //

            if (bThumbnail)
            {
                System.Windows.Media.Imaging.WriteableBitmap wbmp =
                    Microsoft.Phone.PictureDecoder.DecodeJpeg(pic.GetThumbnail(), iCX, iCY);

                return(wbmp);
            }
            else
            {
                BitmapImage bmp = new BitmapImage();
                bmp.SetSource(pic.GetImage());
                return(bmp);
            }
        }
Example #18
0
 private async void LoadThumbnails(PictureAlbum album)
 {
     progress.Text = "Loading images...";
     progress.IsVisible = true;
     var group = new List<ThumbnailData>();
     await Task.Run(() =>
     {
         foreach (var pic in album.Pictures)
         {
             group.Add(new ThumbnailData(pic));
         }
     });
     group.Reverse();
     var groups = new ThumbnailGroup();
     groups.Group = new ObservableCollection<ThumbnailData>(group);
     ImageGrid.DataContext = groups;
     Dispatcher.BeginInvoke(() => { progress.IsVisible = false; });
 }
Example #19
0
        public async Task LoadAlbumsFromMediaLibraryAsync(PictureAlbum album, CancellationToken token)
        {
            ObservableCollection <CollectionControlModel> newItems = new ObservableCollection <CollectionControlModel>();

            foreach (var photo in album.Pictures)
            {
                Log(photo.Name);
                // await Task.Delay(new TimeSpan(0,0,0,0,10));
                token.ThrowIfCancellationRequested();
                Log(photo.Name + "50");
                newItems.Add(new CollectionControlModel()
                {
                    FileName = Path.GetFileNameWithoutExtension(photo.Name),
                    Data     = photo
                });
                Log(photo.Name);
                token.ThrowIfCancellationRequested();
                using (Stream str = photo.GetThumbnail())
                {
                    Log(photo.Name + "60");
                    byte[] buffer = new byte[str.Length];
                    await str.ReadAsync(buffer, 0, buffer.Length);

                    Log(photo.Name + "63");
                    token.ThrowIfCancellationRequested();
                    using (MemoryStream ms = new MemoryStream())
                    {
                        Log(photo.Name + "67");
                        await ms.WriteAsync(buffer, 0, buffer.Length);

                        token.ThrowIfCancellationRequested();
                        newItems.Last().Thumbnail = new BitmapImage();
                        newItems.Last().Thumbnail.SetSource(ms);
                        Log(photo.Name + "72");
                    }
                    //await Task.Delay(new TimeSpan(0, 0, 0, 0, 10));
                    //Thread.Sleep(1000);
                }
            }
            foreach (var item in newItems)
            {
                Items.Add(item);
            }
        }
Example #20
0
 public async Task LoadAlbumsFromMediaLibraryAsync(PictureAlbum album, CancellationToken token)
 {
     ObservableCollection<CollectionControlModel> newItems = new ObservableCollection<CollectionControlModel>();
     foreach (var photo in album.Pictures)
     {
         Log(photo.Name);
        // await Task.Delay(new TimeSpan(0,0,0,0,10));
         token.ThrowIfCancellationRequested();
         Log(photo.Name + "50");
         newItems.Add(new CollectionControlModel()
         {
             FileName = Path.GetFileNameWithoutExtension(photo.Name),
             Data = photo
         });
         Log(photo.Name);
         token.ThrowIfCancellationRequested();
         using (Stream str = photo.GetThumbnail())
         {
            
             Log(photo.Name + "60");
             byte[] buffer = new byte[str.Length];
             await str.ReadAsync(buffer, 0, buffer.Length);
             Log(photo.Name + "63");
             token.ThrowIfCancellationRequested();
             using (MemoryStream ms = new MemoryStream())
             {
                 Log(photo.Name + "67");
                 await ms.WriteAsync(buffer, 0, buffer.Length);
                 token.ThrowIfCancellationRequested();
                 newItems.Last().Thumbnail = new BitmapImage();
                 newItems.Last().Thumbnail.SetSource(ms);
                 Log(photo.Name + "72");
             }
             //await Task.Delay(new TimeSpan(0, 0, 0, 0, 10));
             //Thread.Sleep(1000);
         }
     }
     foreach (var item in newItems)
     {
         Items.Add(item);
     }
 }
Example #21
0
        public static IEnumerable <BaseMediaViewModel <Picture> > GetPictures(PictureAlbum pictureAlbum = null)
        {
            var pictureCollection = pictureAlbum == null ? new MediaLibrary().Pictures : pictureAlbum.Pictures;

            var pictureList = new List <BaseMediaViewModel <Picture> >();

            foreach (var picture in pictureCollection)
            {
                var media = new BaseMediaViewModel <Picture>()
                {
                    Name       = picture.Name,
                    Type       = MediaType.Picture,
                    BaseObject = picture
                };

                pictureList.Add(media);
            }

            return(pictureList);
        }
Example #22
0
        public async Task <IHttpActionResult> PatchPictureAlbum(Guid pictureAlbumId, PictureAlbum pictureAlbum)
        {
            if (ModelState.IsValid && pictureAlbum != null)
            {
                var fetchTask = new Task <dynamic>(() => this.PictureAlbumsRepository.GetPictureAlbum(pictureAlbumId));
                fetchTask.Start();
                var album = await fetchTask;

                album.Id          = pictureAlbumId;
                album.Name        = string.IsNullOrWhiteSpace(pictureAlbum.Name) ? album.Name : pictureAlbum.Name;
                album.Description = string.IsNullOrWhiteSpace(pictureAlbum.Description) ? album.Description : pictureAlbum.Description;
                album.Tags        = pictureAlbum.Tags == null ? album.Tags : pictureAlbum.Tags;

                var updateTask = new Task <Guid>(() => this.PictureAlbumsRepository.UpdatePictureAlbum(pictureAlbum));
                updateTask.Start();
                await updateTask;
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Example #23
0
 public void ResetCachedMediaLibrary()
 {
     try
     {
         if ((this._album != null))
         {
             this._album.Dispose();
             this._album = null;
         }
         if (this._ml == null)
         {
             return;
         }
         this._ml.Dispose();
         this._ml = null;
     }
     catch (Exception)
     {
     }
 }
Example #24
0
        public static BitmapImage GetRandomImage(PictureAlbum pictureAlbum)
        {
            if (pictureAlbum.Pictures.Count < 1)
            {
                return(null);
            }

            var random = new Random(DateTime.Now.Millisecond);

            var bitmapImage = new BitmapImage
            {
                DecodePixelHeight = 200,
                DecodePixelWidth  = 200,
                DecodePixelType   = DecodePixelType.Logical
            };

            // If there is a problem obtaining the random image only will appear the album name
            try { bitmapImage.SetSource(pictureAlbum.Pictures[random.Next(0, pictureAlbum.Pictures.Count)].GetImage()); }
            catch (Exception) { return(null); }

            return(bitmapImage);
        }
        // Stores the callback for the ScheduledAgent and iterates over the photos
        // until the end of the album is reached.
        public void InitializeServiceUpload(NotifyComplete notifyCompleteDelegate)
        {
            notifyCompleteCallBack = notifyCompleteDelegate;

            // Make sure that the required key exists in the IsolatedStorageSettings
            // (i.e., the user is logged in).
            if (settings.Contains(AsyncHttpPostHelper.ConstantStrings.settingsKey))
            {
                // Find the album to upload.
                using (MediaLibrary m = new MediaLibrary())
                    using (PictureAlbum cr = FindAlbum(m))
                    {
                        if (cr.Pictures.Count > 0)
                        {
                            // Save the total number of photos available in the album.
                            totalNumberOfPictures = cr.Pictures.Count;

                            // Decrypt the user's private settings key.
                            byte[] byteAccessToken = ProtectedData.Unprotect((byte[])settings[AsyncHttpPostHelper.ConstantStrings.settingsKey], null);
                            strAccessToken = Encoding.UTF8.GetString(byteAccessToken, 0, byteAccessToken.Length);

                            // Begin the cycle by starting the upload with the first image.
                            counter = 0;
                            UploadPicture(cr, counter);
                        }
                        else
                        {
                            // Album is empty. No pictures to upload.
                        }
                    }
            }
            else
            {
                // User has not logged in. Abort.
                notifyCompleteCallBack();
            }
        }
Example #26
0
        public void GetImage(string path)
        {
            MediaSource mediaSource = MediaSource.GetAvailableMediaSources().First(source => source.MediaSourceType == MediaSourceType.LocalDevice);

            using (MediaLibrary mediaLibrary = new MediaLibrary(mediaSource))
            {
                PictureAlbum      cameraRollAlbum = mediaLibrary.RootPictureAlbum.Albums.First((album) => album.Name == "Camera Roll"); //Get albulm Cameraroll
                PictureCollection pictures        = cameraRollAlbum.Pictures;
                try
                {
                    if (pictures != null)
                    {
                        Picture picture = pictures.FirstOrDefault(p => p.Name == path);
                        var     stream  = picture.GetImage();
                        selectedImage.SetSource(stream);
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show("Camera roll null");
                }
            }
            //return selectedImage;
        }
Example #27
0
 public Picture GetGalleryImage(string albumId, int seqNo)
 {
     if (this._ml == null)
     {
         this._ml = new MediaLibrary();
     }
     if (this._album == null || this._album.Name != albumId)
     {
         if (this._album != null)
         {
             this._album.Dispose();
         }
         this._album = Enumerable.FirstOrDefault <PictureAlbum>(this._ml.RootPictureAlbum.Albums, (PictureAlbum a) => a.Name == albumId);
     }
     if (this._album != null && this._album.Pictures.Count > seqNo)
     {
         Picture picture = this._album.Pictures[seqNo];
         if (picture != null)
         {
             return(picture);
         }
     }
     return(null);
 }
 public StackItem(PictureAlbum oPa, int iIndex)
 {
     pa    = oPa;
     Index = iIndex;
 }
        private static List<Album> GetAlbums(PictureAlbum album)
        {
            List<Album> ret = new List<Album>();

            if (album != null && album.Albums != null && album.Albums.Count > 0)
            {
                foreach (PictureAlbum p in album.Albums)
                {
                    List<Album> r = GetAlbums(p);
                    if (r != null && r.Count > 0)
                    {
                        ret.AddRange(r);
                    }
                }
            }

            if (album.Pictures != null)
            {
                ret.Add(new Album(album));
            }

            return ret;
        }
Example #30
0
 private void PopulatePictures(List<Picture> pictures, PictureAlbum album, int maxCount)
 {
     if (album.Pictures.Count > 0)
     {
         foreach (var picture in album.Pictures)
         {
             pictures.Add(picture);
         }
     }
     if (album.Albums.Count > 0)
     {
         foreach (var childAlbum in album.Albums)
         {
             PopulatePictures(pictures, childAlbum, maxCount);
         }
     }
 }
        private void SaveImage(string sIndiciesToItem, bool bThumbnail)
        {
            RscStore store = new RscStore();

            //string sFolder = RscKnownFolders.GetMediaPath("Zune");
            string sFolder = RscKnownFolders.GetMediaPath("Media Library");

            // //
            //

            PictureAlbum pa  = m_media.RootPictureAlbum;
            Picture      pic = null;

            string [] asInd = sIndiciesToItem.Split('|');
            int       iCnt  = asInd.Length;

            for (int i = 0; i < iCnt; i++)
            {
                if (i == iCnt - 1)
                {
                    sFolder += "\\" + pa.Name;
                    if (!store.FolderExists(sFolder))
                    {
                        store.CreateFolder(sFolder);
                    }

                    pic = pa.Pictures[Int32.Parse(asInd[i])];
                }
                else
                {
                    sFolder += "\\" + pa.Name;
                    if (!store.FolderExists(sFolder))
                    {
                        store.CreateFolder(sFolder);
                    }

                    pa = pa.Albums[Int32.Parse(asInd[i])];
                }
            }

            if (bThumbnail)
            {
                sFolder += "\\" + "tn";
                if (!store.FolderExists(sFolder))
                {
                    store.CreateFolder(sFolder);
                }
            }

            //
            // //

            string sPreExt = "";

            if (bThumbnail)
            {
                sPreExt = ".tn";
            }

            string sFName = pic.Name;
            string sFExt  = "";
            int    iPos   = sFName.LastIndexOf('.');

            if (iPos >= 0)
            {
                sFExt  = sFName.Substring(iPos);
                sFName = sFName.Substring(0, iPos);
            }

            string sPath = sFolder + "\\" + sFName + sPreExt + sFExt;

            iCnt = 0;
            for (;;)
            {
                if (!store.FileExists(sPath))
                {
                    break;
                }
                iCnt++;
                sPath = sFolder + "\\" + sFName + "_" + iCnt.ToString() + sPreExt + sFExt;
            }

            System.IO.Stream strmSrc;
            if (bThumbnail)
            {
                strmSrc = pic.GetThumbnail();
            }
            else
            {
                strmSrc = pic.GetImage();
            }

            System.IO.Stream stream = store.CreateFile(sPath);
            // Initialize the buffer for 4KB disk pages.
            byte[] readBuffer = new byte[4096];
            int    bytesRead  = -1;

            // Copy the image/thumbnail to the local folder.
            while ((bytesRead = strmSrc.Read(readBuffer, 0, readBuffer.Length)) > 0)
            {
                stream.Write(readBuffer, 0, bytesRead);
            }
            stream.Close();

            strmSrc.Close();
        }
 private void LoadImages(PictureAlbum pictureAlbum)
 {
     BackgroundWorker bw = new BackgroundWorker();
     bw.DoWork += new DoWorkEventHandler(bw_DoWork);
     bw.RunWorkerAsync();
 }
        private void NavigateBack()
        {
            if (IsNotInAlbum) App.ViewModel.NavigateBack();

            currentAlbum = null;
            NotifyPropertyChanged(this, "IsNotInAlbum");
            NotifyPropertyChanged(this, "IsInsideAlbum");
            NotifyPropertyChanged(this, "Images");
        }
Example #34
0
        private PictureAlbum GetPictureAlbumObject(string path)
        {
            int length = 0;

            string [] aPath = PathParts(path, out length);

            if (length == 0)
            {
                return(null);
            }
            else
            {
                bool bPictures   = false;
                int  iLevelStart = 0;
                if (length > 0)
                {
                    if (aPath[0].ToLower().CompareTo("pictures") == 0)
                    {
                        bPictures   = true;
                        iLevelStart = 1;
                    }
                }
                if (length > 1)
                {
                    //Known Folder integration...
                    if (aPath[0].ToLower().CompareTo("media library") == 0)
                    {
                        if (aPath[1].ToLower().CompareTo("pictures") == 0)
                        {
                            bPictures   = true;
                            iLevelStart = 2;
                        }
                    }
                }

                if (bPictures)
                {
                    MediaLibrary MedLib = new MediaLibrary();
                    PictureAlbum pa     = MedLib.RootPictureAlbum;

                    bool bHit = false;
                    for (int iPos = iLevelStart; iPos < length; iPos++)
                    {
                        foreach (PictureAlbum paHit in pa.Albums)
                        {
                            if (paHit.Name.ToLower().CompareTo(aPath[iPos].ToLower()) == 0)
                            {
                                bHit = true;
                                pa   = paHit;
                                break;
                            }
                        }
                        if (!bHit)
                        {
                            return(null);                                //Album not found...
                        }
                    }

                    return(pa);
                }
                else
                {
                    return(null);
                }
            }

            //return null;
        }
 public void SelectAlbum(object args)
 {
     backWasPressed = false;
     Images.Clear();
     currentAlbum = Albums.Single(c => c.AlbumName == args.ToString()).Album;
     LoadImages(currentAlbum);
     NotifyPropertyChanged(this, "IsNotInAlbum");
     NotifyPropertyChanged(this, "IsInsideAlbum");
     NotifyPropertyChanged(this, "Images");
 }
Example #36
0
 private void Initialize()
 {
     ThreadPool.QueueUserWorkItem((WaitCallback)(o =>
     {
         try
         {
             Stopwatch stopwatch = Stopwatch.StartNew();
             List <AlbumHeader> albumHeaders = new List <AlbumHeader>();
             using (MediaLibrary mediaLibrary = new MediaLibrary())
             {
                 using (PictureAlbum rootPictureAlbum = mediaLibrary.RootPictureAlbum)
                 {
                     PictureAlbumCollection pictureAlbumCollection = rootPictureAlbum != null ? rootPictureAlbum.Albums : (PictureAlbumCollection)null;
                     if (pictureAlbumCollection != null)
                     {
                         if (pictureAlbumCollection.Count > 0)
                         {
                             using (IEnumerator <PictureAlbum> enumerator = pictureAlbumCollection.GetEnumerator())
                             {
                                 while (((IEnumerator)enumerator).MoveNext())
                                 {
                                     PictureAlbum current = enumerator.Current;
                                     if (current != null)
                                     {
                                         PictureCollection pictures = current.Pictures;
                                         if (pictures != null)
                                         {
                                             string str = current.Name ?? "";
                                             AlbumHeader albumHeader1 = new AlbumHeader();
                                             albumHeader1.AlbumId = str;
                                             albumHeader1.AlbumName = str;
                                             int count = pictures.Count;
                                             albumHeader1.PhotosCount = count;
                                             AlbumHeader albumHeader2 = albumHeader1;
                                             string albumName = albumHeader2.AlbumName;
                                             if (!(albumName == "Camera Roll"))
                                             {
                                                 if (!(albumName == "Saved Pictures"))
                                                 {
                                                     if (!(albumName == "Sample Pictures"))
                                                     {
                                                         if (albumName == "Screenshots")
                                                         {
                                                             albumHeader2.AlbumName = CommonResources.AlbumScreenshots;
                                                             albumHeader2.OrderNo = 3;
                                                         }
                                                         else
                                                         {
                                                             albumHeader2.OrderNo = int.MaxValue;
                                                         }
                                                     }
                                                     else
                                                     {
                                                         albumHeader2.AlbumName = CommonResources.AlbumSamplePictures;
                                                         albumHeader2.OrderNo = 2;
                                                     }
                                                 }
                                                 else
                                                 {
                                                     albumHeader2.AlbumName = CommonResources.AlbumSavedPictures;
                                                     albumHeader2.OrderNo = 1;
                                                 }
                                             }
                                             else
                                             {
                                                 albumHeader2.AlbumName = CommonResources.AlbumCameraRoll;
                                                 albumHeader2.OrderNo = 0;
                                             }
                                             Picture picture = ((IEnumerable <Picture>)pictures).FirstOrDefault <Picture>();
                                             if (picture != null)
                                             {
                                                 try
                                                 {
                                                     albumHeader2.ImageStream = picture.GetThumbnail();
                                                 }
                                                 catch
                                                 {
                                                 }
                                                 try
                                                 {
                                                     picture.Dispose();
                                                 }
                                                 catch
                                                 {
                                                 }
                                             }
                                             albumHeaders.Add(albumHeader2);
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             stopwatch.Stop();
             Execute.ExecuteOnUIThread((Action)(() =>
             {
                 this._albums.Clear();
                 foreach (IEnumerable <AlbumHeader> source in albumHeaders.OrderBy <AlbumHeader, int>((Func <AlbumHeader, int>)(ah => ah.OrderNo)).Partition <AlbumHeader>(2))
                 {
                     List <AlbumHeader> list = source.ToList <AlbumHeader>();
                     AlbumHeaderTwoInARow albumHeaderTwoInArow = new AlbumHeaderTwoInARow()
                     {
                         AlbumHeader1 = list[0]
                     };
                     if (list.Count > 1)
                     {
                         albumHeaderTwoInArow.AlbumHeader2 = list[1];
                     }
                     this._albums.Add(albumHeaderTwoInArow);
                 }
                 this._isLoaded = true;
                 this.NotifyPropertyChanged <string>((Expression <Func <string> >)(() => this.FooterText));
                 this.NotifyPropertyChanged <Visibility>((Expression <Func <Visibility> >)(() => this.FooterTextVisibility));
             }));
         }
         catch (Exception ex)
         {
             Logger.Instance.ErrorAndSaveToIso("Failed to read gallery albums", ex);
         }
     }));
 }
 public Album(PictureAlbum album)
 {
     _album = album;
 }
        private void MakePhotoAlbum(PictureAlbum album)
        {
            PhotoRow currentRow  = null;
            var      stopwatch   = Stopwatch.StartNew();
            var      photoFiles  = new List <PhotoFile>();
            var      photoRow    = new ObservableCollection <PhotoRow>();
            var      secondSlice = new List <PhotoFile>();

            _album = album;
            if (_album.Pictures.Count > 0)
            {
                var cropedFiles = _album.Pictures.OrderByDescending(x => x.Date).ToList();
                var maxCount    = 12;
                for (var i = 0; i < cropedFiles.Count; i++)
                {
                    var p         = cropedFiles[i];
                    var photoFile = new PhotoFile {
                        Picture = p, SuppressAnimation = true, IsSelected = _selectedPictures.ContainsKey(p)
                    };

                    if (i < maxCount)
                    {
                        if (i % 3 == 0)
                        {
                            currentRow = new PhotoRow();
                            photoRow.Add(currentRow);
                        }
                        Stream thumbnail;
                        try
                        {
                            thumbnail = p.GetThumbnail();
                        }
                        catch (Exception e)
                        {
                            Log.Write(string.Format("OpenPhotoPicker File getThumbnail exception album={0} file={1}\n{2}", album.Name, p.Name, e));
                            cropedFiles.RemoveAt(i--);
                            continue;
                        }

                        photoFile.IsForeground = true;
                        photoFile.Thumbnail    = new WeakReference <Stream>(thumbnail);
                        photoFiles.Add(photoFile);
                        currentRow.Add(photoFile);
                        photoFile.Row = currentRow;
                    }
                    else
                    {
                        secondSlice.Add(photoFile);
                    }
                }
            }

            System.Diagnostics.Debug.WriteLine(stopwatch.Elapsed);

            Telegram.Api.Helpers.Execute.BeginOnUIThread(() =>
            {
                CurrentAlbum = album;
                if (photoRow.Count < 4)
                {
                    Photos.VerticalAlignment = VerticalAlignment.Bottom;
                }
                else
                {
                    Photos.VerticalAlignment = VerticalAlignment.Stretch;
                }
                Photos.ItemsSource = photoRow;
                //LayoutRoot.Background = new SolidColorBrush(Color.FromArgb(128, 0, 0, 0));


                Photos.Visibility = Visibility.Visible;
                Photos.Opacity    = 0.0;

                Telegram.Api.Helpers.Execute.BeginOnUIThread(() =>
                {
                    Photos.Opacity         = 1.0;
                    var storyboard         = new Storyboard();
                    var translateAnimaiton = new DoubleAnimationUsingKeyFrames();
                    translateAnimaiton.KeyFrames.Add(new EasingDoubleKeyFrame {
                        KeyTime = TimeSpan.FromSeconds(0.0), Value = Photos.ActualHeight
                    });
                    translateAnimaiton.KeyFrames.Add(new EasingDoubleKeyFrame {
                        KeyTime = TimeSpan.FromSeconds(0.4), Value = 0.0, EasingFunction = new ExponentialEase {
                            Exponent = 5.0, EasingMode = EasingMode.EaseOut
                        }
                    });
                    Storyboard.SetTarget(translateAnimaiton, Photos);
                    Storyboard.SetTargetProperty(translateAnimaiton, new PropertyPath("(UIElement.RenderTransform).(TranslateTransform.Y)"));
                    storyboard.Children.Add(translateAnimaiton);

                    storyboard.Begin();

                    if (secondSlice.Count > 0)
                    {
                        storyboard.Completed += (o, e) =>
                        {
                            for (var i = 0; i < secondSlice.Count; i++)
                            {
                                if (i % 3 == 0)
                                {
                                    currentRow = new PhotoRow();
                                    photoRow.Add(currentRow);
                                }

                                photoFiles.Add(secondSlice[i]);
                                currentRow.Add(secondSlice[i]);
                                secondSlice[i].Row = currentRow;
                            }
                        };
                    }
                });
            });
        }
Example #39
0
 private PictureAlbum GetAlbum(PictureAlbum album, string albumName)
 {
     if (String.Equals(album.Name, albumName))
     {
         return album;
     }
     else
     {
         if (album.Albums.Count > 0)
         {
             return album.Albums.Where(s => String.Equals(s.Name, albumName)).FirstOrDefault();
         }
         else
             return null;
     }
 }
Example #40
0
        public override string [] GetFolderNames(string path, string wildcard, bool bIncludeHidden, bool bStartWithInfChr)
        {
            int length = 0;

            string [] aPath = PathParts(path, out length);

            if (length == 0 && (wildcard.Length == 0 || wildcard == "*.*"))
            {
                if (bStartWithInfChr)
                {
                    return new String [] { "nPictures" }
                }
                ;                                                           //Normal...
                else
                {
                    return new String [] { "Pictures" }
                };
            }
            else if (length == 1 && aPath[0].ToLower().CompareTo("media library") == 0 && (wildcard.Length == 0 || wildcard == "*.*"))
            {
                //Known Folder integration...
                if (bStartWithInfChr)
                {
                    return new String [] { "nPictures" }
                }
                ;                                                           //Normal...
                else
                {
                    return new String [] { "Pictures" }
                };
            }
            else
            {
                bool bPictures   = false;
                int  iLevelStart = 0;
                if (length > 0)
                {
                    if (aPath[0].ToLower().CompareTo("pictures") == 0)
                    {
                        bPictures   = true;
                        iLevelStart = 1;
                    }
                }
                if (length > 1)
                {
                    //Known Folder integration...
                    if (aPath[0].ToLower().CompareTo("media library") == 0)
                    {
                        if (aPath[1].ToLower().CompareTo("pictures") == 0)
                        {
                            bPictures   = true;
                            iLevelStart = 2;
                        }
                    }
                }

                if (bPictures)
                {
                    MediaLibrary MedLib = new MediaLibrary();

                    PictureAlbum pa = MedLib.RootPictureAlbum;

                    bool bHit = false;
                    for (int iPos = iLevelStart; iPos < length; iPos++)
                    {
                        foreach (PictureAlbum paHit in pa.Albums)
                        {
                            if (paHit.Name.ToLower().CompareTo(aPath[iPos].ToLower()) == 0)
                            {
                                bHit = true;
                                pa   = paHit;
                                break;
                            }
                        }
                        if (!bHit)
                        {
                            return new String [] {}
                        }
                        ;                                                            //Album not found...
                    }

                    if (pa.Albums.Count == 0)
                    {
                        return new String [] {}
                    }
                    ;                                                                       //No Sub Album...

                    RscWildCard wc = new RscWildCard(wildcard);

                    string [] astr = new String[pa.Albums.Count];

                    int iLenSave = astr.Length;
                    int i        = 0;
                    foreach (PictureAlbum paHit in pa.Albums)
                    {
                        if (wc.Wanted(paHit.Name))
                        {
                            if (bStartWithInfChr)
                            {
                                astr[i] = "n";                                   //Normal...
                            }
                            else
                            {
                                astr[i] = "";
                            }
                            astr[i] += paHit.Name;

                            i++;
                        }
                    }

                    if (i == 0)
                    {
                        return new String [] {}
                    }
                    ;                                                         //All filtered out...
                    if (i == iLenSave)
                    {
                        return(astr);                                    //All wanted...
                    }
                    //Not so nice... :(
                    string [] astr2 = new String[i];
                    for (int j = 0; j < i; j++)
                    {
                        astr2[j] = astr[j];
                    }

                    return(astr2);
                }
                else
                {
                    return(new String [] {});
                }
            }

            //return new String [] {};
        }
Example #41
0
 private PictureAlbum GetAlbum(string albumName, PictureAlbum album)
 {
     PictureAlbum foundAlbum = null;
     if (String.Equals(album.Name, albumName))
     {
         foundAlbum = album;
     }
     if (foundAlbum == null && album.Albums.Count > 0)
     {
         foreach (var childAlbum in album.Albums)
         {
             foundAlbum = GetAlbum(albumName, childAlbum);
             if (foundAlbum != null)
                 break;
         }
     }
     return foundAlbum;
 }
Example #42
0
        //
        // //
        //

        private Picture GetPictureObject(string path)
        {
            int length = 0;

            string [] aPath = PathParts(path, out length);

            if (length == 0)
            {
                return(null);
            }
            else
            {
                bool bPictures   = false;
                int  iLevelStart = 0;
                if (length > 0)
                {
                    if (aPath[0].ToLower().CompareTo("pictures") == 0)
                    {
                        bPictures   = true;
                        iLevelStart = 1;
                    }
                }
                if (length > 1)
                {
                    //Known Folder integration...
                    if (aPath[0].ToLower().CompareTo("media library") == 0)
                    {
                        if (aPath[1].ToLower().CompareTo("pictures") == 0)
                        {
                            bPictures   = true;
                            iLevelStart = 2;
                        }
                    }
                }

                if (bPictures)
                {
                    MediaLibrary MedLib = new MediaLibrary();
                    PictureAlbum pa     = MedLib.RootPictureAlbum;

                    bool bHit = false;
                    for (int iPos = iLevelStart; iPos < (length - 1); iPos++)
                    {
                        foreach (PictureAlbum paHit in pa.Albums)
                        {
                            if (paHit.Name.ToLower().CompareTo(aPath[iPos].ToLower()) == 0)
                            {
                                bHit = true;
                                pa   = paHit;
                                break;
                            }
                        }
                        if (!bHit)
                        {
                            return(null);                                //Album not found...
                        }
                    }

                    if (pa.Pictures.Count == 0)
                    {
                        return(null);                                             //No Pictures...
                    }
                    int    iPInd = -1;
                    string sFn   = aPath[length - 1];
                    int    iDot  = sFn.IndexOf(')');
                    if (iDot >= 0)
                    {
                        iPInd = Int32.Parse(sFn.Substring(0, iDot));
                        sFn   = sFn.Substring(iDot + 2);
                    }
                    sFn = sFn.ToLower();

                    if (iPInd >= 0 && iPInd < pa.Pictures.Count)
                    {
                        if (pa.Pictures[iPInd].Name.ToLower().CompareTo(sFn) == 0)
                        {
                            return(pa.Pictures[iPInd]);
                        }
                    }

                    foreach (Picture pHit in pa.Pictures)
                    {
                        if (pHit.Name.ToLower().CompareTo(sFn) == 0)
                        {
                            return(pHit);
                        }
                    }

                    return(null);
                }
                else
                {
                    return(null);
                }
            }

            //return null;
        }