Beispiel #1
0
 private void InitList()
 {
     var media = new MediaLibrary();
     var list = media.Pictures;
     List<MediaLibraryThumbnailedImage> imgSources = new List<MediaLibraryThumbnailedImage>();
     foreach (var pic in list)
     {
         imgSources.Add(new MediaLibraryThumbnailedImage(pic));
     }
     mediaViewer.Items = new ObservableCollection<object>(imgSources);
     media.Dispose();
     media = null;
 }
 public static void SaveToPictureLiabray(this UIElement contentToSaveToImage, string folder, string fileName, int width, int height)
 {
     using (System.IO.IsolatedStorage.IsolatedStorageFile file = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication())
     {
         if (!file.DirectoryExists(folder))
         {
             file.CreateDirectory(folder);
         }
         string path = folder + "//" + fileName;
         using (System.IO.IsolatedStorage.IsolatedStorageFileStream stream = file.OpenFile(path, System.IO.FileMode.OpenOrCreate))
         {
             new WriteableBitmap(contentToSaveToImage, null).SaveJpeg(stream, width, height, 0, 0x55);
             stream.Close();
             MediaLibrary library = new MediaLibrary();
             using (System.IO.IsolatedStorage.IsolatedStorageFileStream stream2 = file.OpenFile(path, System.IO.FileMode.Open, System.IO.FileAccess.Read))
             {
                 library.SavePicture(fileName, stream2);
                 library.Dispose();
             }
         }
     }
 }
        private void SaveImageToCameraRoll(int imageHandle, String imageName, Resource imageResource)
        {
            MediaLibrary library = new MediaLibrary();
            MemoryStream targetStream = new MemoryStream();

            int mediaType = MoSync.Constants.MA_MEDIA_TYPE_IMAGE;
            int mediaHandle = imageHandle;
            int eventReturnCode = MoSync.Constants.MA_MEDIA_RES_OK;

            try
            {
                WriteableBitmap data = (WriteableBitmap)imageResource.GetInternalObject();
                data.SaveJpeg(targetStream, data.PixelWidth, data.PixelHeight, 0, 100);
                data = null;

                library.SavePictureToCameraRoll(imageName, targetStream.GetBuffer()).Dispose();
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e.ToString());
                eventReturnCode = MoSync.Constants.MA_MEDIA_RES_IMAGE_EXPORT_FAILED;
            }
            finally
            {
                library.Dispose();
                targetStream.Dispose();
                PostMediaEvent(mediaType, mediaHandle, eventReturnCode);
            }
        }
        private static List<SongEx> GetActualSongList()
        {
            var list = new List<SongEx>();
            MediaLibrary lib = new MediaLibrary();

            if (lib != null)
            {
                uint hMediaList = InteropSvc.InteropLib.Instance.ZMediaLibrary_GetSongs();
                int count = lib.Songs.Count;
                for (int x = 0; x < count; x++)
                {
                    var song = lib.Songs[x];
                    if (!song.IsProtected)
                    {
                        var songEx = new SongEx(song);

                        uint hash = InteropSvc.InteropLib.Instance.ZMediaList_GetHash(hMediaList, x);

                        string hashStr = String.Format("{0:X}", hash).PadLeft(8, '0');

                        string path = "\\My Documents\\Zune\\Content\\" + hashStr.Substring(0, 4) + "\\" + hashStr.Substring(4, 2) + "\\" + hashStr.Substring(6, 2);
                        if (InteropSvc.InteropLib.Instance.GetFileAttributes7(path + ".mp3") != 0xFFFFFFFFU)
                        {
                            path += ".mp3";
                        }
                        else
                        {
                            path += ".wma";
                        }
                        songEx.FilePath = path;

                        list.Add(songEx);
                    }
                }
                InteropSvc.InteropLib.Instance.ZMediaList_Release(hMediaList);
                lib.Dispose();
                list.Sort(new SongExComparer());
            }
            return list;
        }
        protected async override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            if (e.NavigationMode != System.Windows.Navigation.NavigationMode.Back)
            {
                if (this.NavigationContext.QueryString.ContainsKey("FileName"))
                {
                    WorkingDesignName = string.Empty;
                    App.ExitCall = false;

                    OpenFlyer(this.NavigationContext.QueryString["FileName"]);
                }
               
            }
            else if (e.NavigationMode == System.Windows.Navigation.NavigationMode.Back)
            {
                if (App.SaveFileName != "" && App.FromWhere == "SaveHolo")
                {
                    if (App.SaveType == "H") // Save as Hologram
                    {
                        SaveFlyer(App.SaveFileName);

                        WorkingDesignName = App.SaveFileName;
                        //ApplicationTitle.Text = "DESIGNER :: " + App.SaveFileName;

                        if (App.ExitCall == true)
                        {
                            App.ExitCall = false;
                            NavigationService.GoBack();
                        }
                    }
                    else if (App.SaveType == "I") // Save as Image
                    {
                        MemoryStream ms = new MemoryStream();
                        WriteableBitmap wbmpThumbnail = new WriteableBitmap(this.ContentPanel, null);
                        wbmpThumbnail.SaveJpeg(ms, wbmpThumbnail.PixelWidth, wbmpThumbnail.PixelHeight, 0, 100);

                        ms.Seek(0, 0);
                        MediaLibrary mediaLibrary = new MediaLibrary();
                        Picture pic = mediaLibrary.SavePicture(App.SaveFileName + ".jpg", ms);

                        mediaLibrary.Dispose();
                        pic.Dispose();
                        ms.Flush();
                        ms.Close();
                        ms.Dispose();
                    }
                    else if (App.SaveType == "C") // Save in Cloud
                    {
                        if (App.SaveFileName.EndsWith(".4dh"))
                            WorkingDesignName = App.SaveFileName;
                        else
                            WorkingDesignName = App.SaveFileName + ".4dh";

                        SaveFlyer(WorkingDesignName);
                        
                        //ApplicationTitle.Text = "DESIGNER :: " + App.SaveFileName;

                        if (App.ExitCall == true)
                        {
                            App.ExitCall = false;
                            NavigationService.GoBack();
                        }

                        using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
                        {
                            using (IsolatedStorageFileStream stream = myIsolatedStorage.OpenFile(WorkingDesignName, FileMode.Open,FileAccess.Read,FileShare.Read))
                            {
                                try{
                                    //LiveOperationResult res = await App.client.BackgroundUploadAsync("me/skydrive", new Uri("/shared/transfers/" + WorkingDesignName, UriKind.Relative), OverwriteOption.Overwrite);
                                    var res = await App.client.UploadAsync("me/skydrive", WorkingDesignName, stream, OverwriteOption.Overwrite);
                                    
                                    //InfoText.Text = "File " + WorkingDesignName + " uploaded";

                                    myIsolatedStorage.DeleteFile(WorkingDesignName);
                                }
                                catch (Exception){}
                            }
                        }

                    }

                }
                else if (App.SaveFileName == "" && App.FromWhere == "SaveFlyer")
                {
                    if (App.ExitCall == true)
                    {
                        App.ExitCall = false;
                        //App.ChangesSaved = false;

                        NavigationService.GoBack();
                    }
                }
            }

            App.SaveType = "H";
            App.FromWhere = "";
            base.OnNavigatedTo(e);
        }