/// <summary> /// 从XNA媒体库中取到图片. /// 并且重新定义到目前大小. /// </summary> /// <param name="name">图片名称</param> /// <returns>通过stream定义图片大小, jpeg格式.</returns> public static Stream GetResizedImage(string name) { MediaLibrary mediaLibrary = new MediaLibrary(); PictureCollection pictureCollection = mediaLibrary.Pictures; Picture picture = pictureCollection.Where(p => p.Name == name).FirstOrDefault(); if (picture == null) { throw new InvalidOperationException(string.Format("不能加载图片 {0}. 图片可能被删除", name)); } Stream originalImageStream = picture.GetImage(); BitmapImage bmp = new BitmapImage(); bmp.SetSource(originalImageStream); WriteableBitmap originalImage = new WriteableBitmap(bmp); MemoryStream targetStream = new MemoryStream(); originalImage.SaveJpeg(targetStream, ResizedImageWidth, ResizedImageHeight, 0, 100); // 现在图片被移到WriteableBitmap类, 原图片的stream被关闭. originalImageStream.Close(); targetStream.Position = 0; return(targetStream); }
public void ClearPhotoStream() { App.PhotoStreamHelper.RemoveAll(); _currentMosaicViewModel = null; if (_pictures != null) { _pictures.Dispose(); _pictures = null; } if (_enumerator != null) { _enumerator.Dispose(); _enumerator = null; } try { ListBoxItems.Clear(); } catch (Exception ex) { } GC.Collect(); }
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"); } } }
void OnAppbarSaveClick(object sender, EventArgs args) { int fileNameNumber = 0; MediaLibrary mediaLib = new MediaLibrary(); PictureCollection savedPictures = mediaLib.SavedPictures; foreach (Picture picture in savedPictures) { string filename = Path.GetFileNameWithoutExtension(picture.Name); int num; if (filename.StartsWith("Posterizer")) { if (Int32.TryParse(filename.Substring(10), out num)) { fileNameNumber = Math.Max(fileNameNumber, num); } } } string saveFileName = String.Format("Posterizer{0:D3}", fileNameNumber + 1); string uri = "/Petzold.Phone.Silverlight;component/SaveFileDialog.xaml" + "?FileName=" + saveFileName; this.NavigationService.Navigate(new Uri(uri, UriKind.Relative)); }
private void RefreshLastImageTaken() { PictureAlbumCollection allAlbums = _mediaLibrary.RootPictureAlbum.Albums; foreach (var album in allAlbums) { if (album.Name.ToUpper().Contains("CAMERA")) { if (album.Pictures != null) { if (album.Pictures.Count() > 0) { PictureCollection allPictures = album.Pictures; Picture picture = allPictures[allPictures.Count() - 1]; Stream picToDisplay = picture.GetImage(); var imageToShow = new Image { Source = PictureDecoder.DecodeJpeg(picToDisplay, picture.Width, picture.Height) }; //if (imageToShow != null) //{ // LastPictureTaken = imageToShow; //} } } } } }
void pc_Completed(object sender, PhotoResult e) { if (e.TaskResult == TaskResult.OK) { MediaLibrary ml = new MediaLibrary(); PictureCollection pic_c = ml.Pictures; foreach (Picture p in pic_c) { var fname = e.OriginalFileName.Substring(e.OriginalFileName.LastIndexOf('\\') + 1); if (p.Name == fname) { QuickImport.pics.Add(p); selected = 1; break; } } long totalsize = 0; foreach (Picture p in QuickImport.pics) { totalsize += p.GetImage().Length; } if (totalsize <= System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication().AvailableFreeSpace) { this.NavigationService.Navigate(new Uri("/System/QuickExtract.xaml", UriKind.Relative)); } else { MessageBox.Show(UVEngine.Resources.UVEngine.spacenotenough); } } else { this.NavigationService.GoBack(); } }
public QuickImport() { InitializeComponent(); pics.Clear(); MediaLibrary ml = new MediaLibrary(); tip.Text += (storage.AvailableFreeSpace / 1048576).ToString() + "MB"; PictureCollection pic_c = ml.Pictures; this.Dispatcher.BeginInvoke(() => { foreach (Picture pic in pic_c) { if (pic.Album.Name.ToUpperInvariant() == "UVE") { pics.Add(pic); } } if (pics.Count == 0) { items.Text = UVEngine.Resources.UVEngine.nopicfound; } else { impButton.IsEnabled = true; selButton.IsEnabled = true; foreach (Picture pic in pics) { items.Text += pic.Name + " " + (pic.GetImage().Length / 1048576).ToString() + "MB" + '\n'; } } }); }
/// <summary> /// Attempts to get a Picture with the provided name from this collection. /// </summary> /// <param name="collection">The PictureCollection to attempt to get the picture from.</param> /// <param name="name">The name of the picture to get.</param> /// <returns>The picture with provided name, or null if not found.</returns> public static Picture Get(this PictureCollection collection, string name) { // If saved picture exists, don't save it to the MediaLibrary. foreach (Picture pic in collection) { if (pic.Name == name) { return(pic); } } return(null); }
/// <summary> /// 获取excel中的图片 /// </summary> /// <returns></returns> public List <byte[]> GetPictureData() { List <byte[]> imgData = new List <byte[]>(); //读取excel中图片 PictureCollection pictures = sheet.Pictures; foreach (Picture pic in pictures) { imgData.Add(pic.Data); } return(imgData); }
/// <summary> /// Whether this colleciton contains the provided picture. /// </summary> /// <param name="collection">This collection.</param> /// <param name="picture">The picture to search for.</param> /// <returns>True if this collection contains the provided picture, false otherwise.</returns> public static bool Contains(this PictureCollection collection, Picture picture) { // If saved picture exists, don't save it to the MediaLibrary. foreach (Picture pic in collection) { if (pic == picture) { return(true); } } return(false); }
/// <summary> /// 读取excel指定工作表中图片 /// </summary> /// <param name="sheetName"></param> /// <returns></returns> public List <byte[]> GetPictureData(string sheetName) { List <byte[]> imgData = new List <byte[]>(); if (workbook.Worksheets[sheetName] != null) { //读取excel中图片 sheet = workbook.Worksheets[sheetName]; PictureCollection pictures = sheet.Pictures; imgData.AddRange(pictures.Select(pic => pic.Data)); } return(imgData); }
public void Run(string cam1dir, string cam2dir, string outdir) { PictureCollection pics = new PictureCollection(); string ext; foreach (string f in Directory.GetFiles(cam1dir)) { ext = Path.GetExtension(f).ToLower(); if (ext.Equals(".jpg") || ext.Equals(".jpeg")) { pics.AddFromFile(f); } } foreach (string f in Directory.GetFiles(cam2dir)) { ext = Path.GetExtension(f).ToLower(); if (ext.Equals(".jpg") || ext.Equals(".jpeg")) { pics.AddFromFile(f); } } if (pics.Count > 0) { if (!Directory.Exists(outdir)) { Directory.CreateDirectory(outdir); } List<Picture> list; foreach (KeyValuePair<long, List<Picture>> kvp in pics) { list = kvp.Value; if (list.Count == 1) { this.CopyFile(list[0].Filename, outdir, list[0].DateTime, -1); } else { for (int i=0; i!=list.Count; i++) { this.CopyFile(list[i].Filename, outdir, list[i].DateTime, i); } } } } }
private static PictureCollection DBMapping(DBPictureCollection dbCollection) { if (dbCollection == null) return null; PictureCollection collection = new PictureCollection(); foreach (DBPicture dbItem in dbCollection) { Picture item = DBMapping(dbItem); collection.Add(item); } return collection; }
private static PictureCollection DBMapping(DBPictureCollection dbCollection) { if (dbCollection == null) { return(null); } PictureCollection collection = new PictureCollection(); foreach (DBPicture dbItem in dbCollection) { Picture item = DBMapping(dbItem); collection.Add(item); } return(collection); }
void GetRandomPicture() { PictureCollection pictures = mediaLib.Pictures; if (pictures.Count > 0) { int index = rand.Next(pictures.Count); Picture pic = pictures[index]; BitmapImage bmp = new BitmapImage(); bmp.SetSource(pic.GetImage()); img.Source = bmp; txtblk.Text = String.Format("{0}\n{1}\n{2}", pic.Name, pic.Album.Name, pic.Date); } }
public Gallery() { InitializeComponent(); pictures = mediaLib.Pictures; foreach (Microsoft.Xna.Framework.Media.Picture picture in pictures) { BitmapImage bmpImage = new BitmapImage(); bmpImage.SetSource(picture.GetThumbnail()); thumbnailCollection.Add(new allListItemTemplete() { name = picture.Name, source = bmpImage }); } allList.ItemsSource = thumbnailCollection; }
private void nextOrPrevius(bool i_Action) { try { if (((m_CurrentControl == PictureCollection.Controls[PictureCollection.Controls.Count - 1]) && (i_Action == true)) || ((m_CurrentControl == PictureCollection.Controls[0]) && (i_Action == false))) { throw new Exception(); } m_CurrentControl = (PictureCollection.GetNextControl((m_CurrentControl), i_Action)); photoBindingSource.Position = PictureCollection.Controls.GetChildIndex(m_CurrentControl); MainPictureBox.Image = (m_CurrentControl as PictureBox).Image; } catch (Exception ex) { MessageBox.Show("This is the last/first photo"); } }
public static void Main(string[] args) { string cam1dir = "/home/pingvinen/Desktop/camera1"; string cam2dir = "/home/pingvinen/Desktop/camera2"; string outdir = "/home/pingvinen/Desktop/cam1_and_cam2_merged"; PictureCollection pics = new PictureCollection(); foreach (string f in Directory.GetFiles(cam1dir)) { pics.AddFromFile(f); } foreach (string f in Directory.GetFiles(cam2dir)) { pics.AddFromFile(f); } if (pics.Count > 0) { if (!Directory.Exists(outdir)) { Directory.CreateDirectory(outdir); } List<Picture> list; foreach (KeyValuePair<long, List<Picture>> kvp in pics) { list = kvp.Value; if (list.Count == 1) { CopyFile(list[0].Filename, outdir, list[0].DateTime, -1); } else { for (int i=0; i!=list.Count; i++) { CopyFile(list[i].Filename, outdir, list[i].DateTime, i); } } } } }
public void GetScreenShots() { try { PictureAlbumCollection allAlbums = _mediaLibrary.RootPictureAlbum.Albums; ScreenShots.Clear(); foreach (var album in allAlbums) { if (album.Name.ToUpper().Contains("SCREENSHOT")) { PictureCollection screenShots = album.Pictures; foreach (var picture in screenShots) { Stream picToDisplay = picture.GetImage(); BitmapImage bmImage = new BitmapImage(); bmImage.SetSource(picToDisplay); var imageToShow = new Image { Source = PictureDecoder.DecodeJpeg(picToDisplay, picture.Width, picture.Height) }; ScreenShots.Add(new ScreenShot(picture.Name, new Uri(MediaLibraryExtensions.GetPath(picture), UriKind.Absolute), imageToShow)); } } } if (ScreenShots.Count() >= 1) { SelectedScreenShot = ScreenShots[ScreenShots.Count - 1]; } else { NoScreenShotVisibility = Visibility.Visible; } } catch (Exception ex) { } }
public void RefreshPhotoStream() { ClearPhotoStream(); using (MediaLibrary library = new MediaLibrary()) { foreach (PictureAlbum album in library.RootPictureAlbum.Albums) { if (album.Name == "Camera Roll") { _pictures = album.Pictures; _enumerator = _pictures.Reverse().GetEnumerator(); AddPhotoSet(); break; } } } }
private void PhoneApplicationPage_Loaded(object sender, System.Windows.RoutedEventArgs e) { int mediaCount = App.MediaCollection.Count; if (mediaCount < 2) { throw new InvalidOperationException("您必须至少选择两个媒体文件."); } MediaLibrary mediaLibrary = new MediaLibrary(); this._pictureCollection = mediaLibrary.Pictures; // 设置前后台的图片. if (App.MediaCollection[0].ResizedImage != null) { this.foregroundImage.Source = App.MediaCollection[0].ResizedImage; } else { WriteableBitmap bmp = this.GetResizedImage(App.MediaCollection[0]); this.foregroundImage.Source = bmp; } if (App.MediaCollection[1].ResizedImage != null) { this.backgroundImage.Source = App.MediaCollection[1].ResizedImage; } else { WriteableBitmap bmp = this.GetResizedImage(App.MediaCollection[1]); this.backgroundImage.Source = bmp; } // 设置_currentImageIndex为2, 下次我们可以从App.MediaCollection[2]开始. this._currentImageIndex = 2; this._dispatcherTimer = new DispatcherTimer(); this._dispatcherTimer.Interval = App.MediaCollection[0].PhotoDuration; this._dispatcherTimer.Tick += new EventHandler(DispatcherTimer_Tick); this._dispatcherTimer.Start(); }
static void Main(string[] args) { List <string> lines = System.IO.File.ReadAllLines(@"C:\Users\manoj_patel\source\repos\SEQualificationTest\SEQualificationTest\InputFile.txt", Encoding.ASCII).ToList(); int count = 0; var inputData = new PictureCollection { Count = 0, Pictures = new List <Picture>() }; foreach (string line in lines) { // Use a tab to indent each line of the file. if (count == 0) { inputData.Count = Convert.ToInt32(line); count++; continue; } var lineArray = line.Split(null); var picture = new Picture { Id = count - 1, Direction = char.Parse(lineArray[0]), TagCount = int.Parse(lineArray[1]), Tags = new List <string>() }; int index = 2; while (index < picture.TagCount + 2) { picture.Tags.Add(lineArray[index]); index++; } count++; } }
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; }
/// <summary> /// Initializes the media library. /// </summary> private void InitializeMediaLibrary() { this.mediaLibrary = new MediaLibrary(); this.pictures = mediaLibrary.Pictures; int currentIndex = 0; // Search for the picture specified in the settings file. // Store the pictures into a list, so that we can easily navigate back and forward (the collection allows only forward navigation). foreach (Picture picture in this.pictures) { if ((this.settings.Background != null) && (this.settings.Background != "") && (picture.Name == this.settings.Background)) { this.currentlySelectedPictureIndex = currentIndex; } currentIndex++; } this.playlists = this.mediaLibrary.Playlists; }
private void pc_Completed_TImport(object sender, PhotoResult e) { QuickImport.pics.Clear(); if (e.TaskResult == TaskResult.OK) { MediaLibrary ml = new MediaLibrary(); PictureCollection pic_c = ml.Pictures; try { for (int i = 0; i < pic_c.Count; i++) { string fname = ""; if (e.OriginalFileName.Contains('\\')) { fname = e.OriginalFileName.Substring(e.OriginalFileName.LastIndexOf('\\') + 1); } else { fname = e.OriginalFileName; } if (pic_c[i].Name == fname) { QuickImport.pics.Add(pic_c[i]); break; } } //foreach (Picture p in pic_c) //{ // string fname = ""; // if (e.OriginalFileName.Contains('\\')) // fname = e.OriginalFileName.Substring(e.OriginalFileName.LastIndexOf('\\') + 1); // else fname = e.OriginalFileName; // if (p.Name == fname) // { // QuickImport.pics.Add(p); // break; // } //} } catch (Exception exception) { MessageBox.Show(exception.Message); } long totalsize = 0; foreach (Picture p in QuickImport.pics) { totalsize += p.GetImage().Length; } if (totalsize <= System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication().AvailableFreeSpace) { this.Dispatcher.BeginInvoke(() => { Thread.Sleep(2000); this.NavigationService.Navigate(new Uri("/System/QuickExtract.xaml", UriKind.Relative)); }); } else { MessageBox.Show(UVEngine.Resources.UVEngine.spacenotenough); } } }
private void ApplySettings() { Size = new Size(columns * width, rows * height); if (Size.Width == 0 || Size.Height == 0) { return; } if (pictureCollection == null || pictureCollection.Width != width || pictureCollection.Height != height) { pictureCollection = new PictureCollection(this, rows, columns); } if (Image == null || Image.Height != Size.Height || Image.Width != Size.Width) { Image = new Bitmap(Size.Width, Size.Height); } }
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 void LoadContent(ContentManager content, string modelName, string pictureName) { Model = content.Load<Model>(modelName); PictureWindowType = modelName; BoundingBox = new BoundingBox(); // scale = new Vector3(); // transformMatrix = new Matrix(); // bb_size_min = GetBoundingBoxSize(Model, transformMatrix).Min; // bb_size_max = GetBoundingBoxSize(Model, transformMatrix).Max; Position = new Vector3(0, 12, 0); Rotation = new Vector3(0, 0, 0); scale = new Vector3(1.0f, 1.0f, 1.0f); bb_size = new Vector3(8, 6, 0.02f); // Load a picture mediaSources = MediaSource.GetAvailableMediaSources(); mediaLib = new MediaLibrary(); picCollection = mediaLib.Pictures; currentPic = 1; //pic = Texture2D.FromStream(GraphicsDevice, picCollection[currentPic].GetImage()); pic = content.Load<Texture2D>(pictureName); //pictureWindowIsActive = false; //pictureWindowIsOnFront = false; //gestureScaleAccelerationFactor = 1.0f; gestureScaleIncrement = 0.004f; timer = new Timer(); }
/// <summary> /// This function is used to get the picture image based on the associated cell /// </summary> /// <param name="pictureCollection"></param> /// <param name="row"></param> /// <returns></returns> private Picture GetPicture(PictureCollection pictureCollection, int row) { Picture returnPic = null; foreach (Picture pic in pictureCollection) { if (pic.UpperLeftRow == row + 1) { returnPic = pic; break; } } return returnPic; }