public static BitmapImage GetImage(string url) { // When in design mode of Visual Studio or Blend if (ViewModelBase.IsInDesignModeStatic) { // The image to be returned to the image control BitmapImage image = new BitmapImage(); image.UriSource = new Uri(url); return image; } // Get the filename and path string filename = Path.GetFileName(url); string fullpath = Path.Combine("Shared", filename); // The file doesn't exists. // Check if is in the queue to be downloaded. if (queue.ContainsKey(fullpath)) { // Return the image associated with this path System.Diagnostics.Debug.WriteLine("Exist in cache " + fullpath); return queue[fullpath]; } //Try to get the file from isolated storage if it exists, if no it will check in the download queue using (IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication()) { // The image to be returned to the image control BitmapImage image = new BitmapImage(); Uri uri = new Uri("Icons/ArtPlaceholder.jpg", UriKind.Relative); StreamResourceInfo resourceInfo = Application.GetResourceStream(uri); image.SetSource(resourceInfo.Stream); if (iso.FileExists(fullpath)) { //The file exists. Read the file and return the stream to the image System.Diagnostics.Debug.WriteLine("Image Loaded from storage " + fullpath); using (IsolatedStorageFileStream stream = iso.OpenFile(fullpath, FileMode.Open)) { // The image to be returned to the image control image.SetSource(stream); //queue.Add(url, image); } } else { // It isn't being downloaded. // Download it ImageDownloadHelper.DownloadImage(url, image); } // Save the name in the queue queue.Add(fullpath, image); return image; } }
public SplashScreen() { LoadConfigPrefs(); Image SplashScreen = new Image() { Height = Application.Current.Host.Content.ActualHeight, Width = Application.Current.Host.Content.ActualWidth, Stretch = Stretch.Fill }; var imageResource = GetSplashScreenImageResource(); if (imageResource != null) { BitmapImage splash_image = new BitmapImage(); splash_image.SetSource(imageResource.Stream); SplashScreen.Source = splash_image; } // Instansiate the popup and set the Child property of Popup to SplashScreen popup = new Popup() { IsOpen = false, Child = SplashScreen, HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Center }; }
protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); if (e.NavigationMode == NavigationMode.New) { XElement article = XElement.Load("Resources/about_program.xml"); XElement Credits = article.Element("Credits"); CreditsAbout.Text = Credits.Element("text").Value; CreditsCopyright.Text = "\u00A9" + CreditsCopyright.Text; CreditsText.Content = "\"" + CreditsText.Content + "\""; Version.Text = AppResources.Version + ": " + article.Element("version").Value; XElement developer = article.Element("developer"); Stream stream = Application.GetResourceStream(new Uri(developer.Element("logo").Attribute("src").Value, UriKind.Relative)).Stream; BitmapImage bmp = new BitmapImage(); bmp.SetSource(stream); stream.Close(); DeveloperLogo.Source = bmp; DeveloperLogo.Stretch = Stretch.Uniform; } }
public static BitmapSource LoadImage(string imageName) { StreamResourceInfo resourceInfo = Application.GetResourceStream(new Uri("Core;component/resources/" + imageName, UriKind.Relative)); var image = new BitmapImage(); image.SetSource(resourceInfo.Stream); return image; }
public static void DownloadImageCallback(IAsyncResult result) { try { HttpWebRequest req = (HttpWebRequest)result.AsyncState; HttpWebResponse responce = (HttpWebResponse)req.EndGetResponse(result); Stream stream = responce.GetResponseStream(); string fileName = Path.GetFileName(responce.ResponseUri.AbsoluteUri.ToString()); Deployment.Current.Dispatcher.BeginInvoke(() => { BitmapImage bmp = new BitmapImage(); bmp.SetSource(stream); if (!IsolatedStorageHelper.isFileAlreadySaved(responce.ResponseUri.AbsoluteUri.ToString())) { IsolatedStorageHelper.saveImage(bmp, fileName); } }); addDownloadedItemsToFilmCollection(responce.ResponseUri.AbsoluteUri.ToString()); } catch (System.Net.WebException e) { Deployment.Current.Dispatcher.BeginInvoke(() => { MessageBox.Show(e.Message.ToString()); }); } }
public static BitmapImage ByteArraytoBitmap(Byte[] byteArray) { MemoryStream stream = new MemoryStream(byteArray); BitmapImage bitmapImage = new BitmapImage(); bitmapImage.SetSource(stream); return bitmapImage; }
void camera_Completed(object sender, PhotoResult e) { if (e.TaskResult == TaskResult.OK) { //Code to display the photo on the page in an image control named myImage. System.Windows.Media.Imaging.BitmapImage bmp = new System.Windows.Media.Imaging.BitmapImage(); bmp.SetSource(e.ChosenPhoto); using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication()) { if (!isoStore.DirectoryExists(item.Group.Title)) { isoStore.CreateDirectory(item.Group.Title); } string fileName = string.Format("{0}/{1}.jpg", item.Group.Title, DateTime.Now.ToString("dd-MM-yyyy HH-mm-ss")); using (IsolatedStorageFileStream targetStream = isoStore.CreateFile(fileName)) { WriteableBitmap wb = new WriteableBitmap(bmp); wb.SaveJpeg(targetStream, wb.PixelWidth, wb.PixelHeight, 0, 100); targetStream.Close(); } if (null == item.UserImages) { item.UserImages = new System.Collections.ObjectModel.ObservableCollection <string>(); } item.UserImages.Add(fileName); } } }
void WebClientOpenReadCompleted(object sender, OpenReadCompletedEventArgs e) { const string tempJpeg = "TempJPEG"; var streamResourceInfo = new StreamResourceInfo(e.Result, null); var userStoreForApplication = IsolatedStorageFile.GetUserStoreForApplication(); if (userStoreForApplication.FileExists(tempJpeg)) { userStoreForApplication.DeleteFile(tempJpeg); } var isolatedStorageFileStream = userStoreForApplication.CreateFile(tempJpeg); var bitmapImage = new BitmapImage { CreateOptions = BitmapCreateOptions.None }; bitmapImage.SetSource(streamResourceInfo.Stream); var writeableBitmap = new WriteableBitmap(bitmapImage); writeableBitmap.SaveJpeg(isolatedStorageFileStream, writeableBitmap.PixelWidth, writeableBitmap.PixelHeight, 0, 85); isolatedStorageFileStream.Close(); isolatedStorageFileStream = userStoreForApplication.OpenFile(tempJpeg, FileMode.Open, FileAccess.Read); // Save the image to the camera roll or saved pictures album. var mediaLibrary = new MediaLibrary(); // Save the image to the saved pictures album. mediaLibrary.SavePicture(string.Format("SavedPicture{0}.jpg", DateTime.Now), isolatedStorageFileStream); isolatedStorageFileStream.Close(); }
public void BeginSaveJpeg() { BitmapImage backgroundImage = new System.Windows.Media.Imaging.BitmapImage(); IAsyncResult result = Microsoft.Xna.Framework.GamerServices.Guide.BeginShowMessageBox("Question", "Do you wish choose a picture from the album?", new string[] { "yes", "no" }, 0, Microsoft.Xna.Framework.GamerServices.MessageBoxIcon.Alert, null, null); result.AsyncWaitHandle.WaitOne(); int?choice = Microsoft.Xna.Framework.GamerServices.Guide.EndShowMessageBox(result); if (choice.HasValue) { if (choice.Value == 0) { PhotoChooserTask photoChooserTask = new PhotoChooserTask(); photoChooserTask.Completed += (s, e) => { if (e.TaskResult == TaskResult.OK) { backgroundImage.SetSource(e.ChosenPhoto); BackgroundImage.Source = backgroundImage; ReplaceImage(); } }; photoChooserTask.Show(); } else { SaveDefault(backgroundImage); } } return; }
void camera_Completed(object sender, PhotoResult e) { if (e.TaskResult == TaskResult.OK) { //Code to display the photo on the page in an image control named myImage. System.Windows.Media.Imaging.BitmapImage bmp = new System.Windows.Media.Imaging.BitmapImage(); bmp.SetSource(e.ChosenPhoto); using (System.IO.IsolatedStorage.IsolatedStorageFile isoStore = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication()) { if (!isoStore.DirectoryExists(item.Group.Title)) isoStore.CreateDirectory(item.Group.Title); string fileName = string.Format("{0}/{1}.jpg", item.Group.Title, DateTime.Now.ToString("dd-MM-yyyy HH-mm-ss")); using (System.IO.IsolatedStorage.IsolatedStorageFileStream targetStream = isoStore.CreateFile(fileName)) { WriteableBitmap wb = new WriteableBitmap(bmp); wb.SaveJpeg(targetStream, wb.PixelWidth, wb.PixelHeight, 0, 100); targetStream.Close(); } if (null == item.UserImages) item.UserImages = new System.Collections.ObjectModel.ObservableCollection<string>(); item.UserImages.Add(fileName); } } }
private void ImportImageButtonClick(object sender, RoutedEventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); #if WPF openFileDialog.Filter = "Image Files (*.png, *.jpg, *.bmp)|*.png;*.jpg;*.bmp"; #else openFileDialog.Filter = "Image Files (*.png, *.jpg)|*.png;*.jpg"; #endif bool? dialogResult = openFileDialog.ShowDialog(); if (dialogResult.HasValue && dialogResult.Value == true) { Image image = new Image(); #if WPF image.Source = new BitmapImage(new Uri(openFileDialog.FileName, UriKind.Absolute)); #else using (var fileOpenRead = openFileDialog.File.OpenRead()) { BitmapImage bitmap = new BitmapImage(); bitmap.SetSource(fileOpenRead); image.Source = bitmap; } #endif Viewbox viewBox = new Viewbox() { Stretch = Stretch.Fill, Margin = new Thickness(-4) }; viewBox.Child = image; RadDiagramShape imageShape = new RadDiagramShape() { Content = viewBox }; this.diagram.Items.Add(imageShape); } }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { byte[] binaryData = (byte[]) value; if (binaryData == null) { return null; } BitmapImage image = null; if (IsJpegOrPngImage(binaryData)) { Stream stream = null; try { stream = new MemoryStream(binaryData); image = new BitmapImage(); image.SetSource(stream); } catch (Exception) { image = null; } finally { if (stream != null) { stream.Dispose(); } } } return image; }
private void SetSourceStr(string sourceStr) { if (imageCache.ContainsKey(sourceStr) == true) { SourceImage.Source = imageCache[sourceStr]; } else { using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication()) { if (isf.FileExists(sourceStr) == false) { SourceImage.Source = null; } else { BitmapImage source = new BitmapImage(); using (IsolatedStorageFileStream isfStream = new IsolatedStorageFileStream(sourceStr, System.IO.FileMode.Open, isf)) { source.SetSource(isfStream); } imageCache.Add(sourceStr, source); SourceImage.Source = source; } } } }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { try { BitmapImage img = new BitmapImage(); string filePath = (string)value; using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication()) { if (isf.FileExists(filePath)) { using (IsolatedStorageFileStream stream = isf.OpenFile(filePath, FileMode.Open, FileAccess.Read)) { img.SetSource(stream); } } else { img = null; } } return img; } catch (Exception ex) { MessageBox.Show(ex.Message); return null; } }
public static BitmapImage CachedImage(string Address) { if (Address == "/Images/Grey.png") { return new BitmapImage(new Uri("/Images/Grey.png", UriKind.Relative)); } string ParsedUrl = ParseAddress(Address); using (IsolatedStorageFile isolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication()) { if (isolatedStorageFile.FileExists("imgCache/" + ParsedUrl)) { try { using (IsolatedStorageFileStream FileStream = IsolatedStorageFile.GetUserStoreForApplication().OpenFile("imgCache\\" + ParsedUrl, FileMode.Open, FileAccess.Read)) { BitmapImage _Bitmap = new BitmapImage(); _Bitmap.SetSource(FileStream); return _Bitmap; } } catch { BitmapImage _Bitmap = new BitmapImage(); _Bitmap.ImageOpened += CachedImageOpened; _Bitmap.UriSource = new Uri(Address, UriKind.RelativeOrAbsolute); return _Bitmap; } } else { BitmapImage _Bitmap = new BitmapImage(); _Bitmap.ImageOpened += CachedImageOpened; _Bitmap.UriSource = new Uri(Address, UriKind.RelativeOrAbsolute); return _Bitmap; } } }
private void UpdateBgImage() { if (this.VM != null && this.VM.FeedbackImage != null && this.VM.FeedbackImage.DataBytes != null) { BitmapImage image = new BitmapImage(); var imgStream = new MemoryStream(this.VM.FeedbackImage.DataBytes); image.SetSource(imgStream); double imgwidth, imgheight, width, height = 0; width = imgwidth = image.PixelWidth; height = imgheight = image.PixelHeight; if (Math.Max(imgwidth, imgheight) > ScreenResolution.Height) { if (imgwidth > imgheight) { width = ScreenResolution.Height; height = ScreenResolution.Height * (imgheight / imgwidth); } else { height = ScreenResolution.Height; width = ScreenResolution.Height * (imgwidth / imgheight); } } ImageArea.Width = width; ImageArea.Height = height; ImageBrush.ImageSource = image; } }
private async void SaveDeal_Click(object sender, RoutedEventArgs e) { var deal = new Deal(Guid.NewGuid().ToString("N")); deal.IssuerName = "Fake Wein Club"; deal.IsUsed = false; deal.MerchantName = "Fake Wein Club"; deal.TermsAndConditions = "Pro Tag und Person ist ein Deal einlösbar."; deal.ExpirationDate = DateTime.Now.AddDays(14); deal.DisplayName = "10€ Nachlass"; deal.Description = "Sie erhalten auf Ihren nächsten Einkauf 10€ erlassen."; deal.Code = "QRNachlass10"; var qrCode = new BitmapImage(); using (Stream logoStream = Application.GetResourceStream(new Uri("Assets/QRNachlass.png", UriKind.Relative)).Stream) { qrCode.SetSource(logoStream); } deal.BarcodeImage = qrCode; try { SystemTray.ProgressIndicator.IsVisible = true; await deal.SaveAsync(); } catch (Exception ex) { MessageBox.Show("Es gab ein Problem beim Speichern: " + ex.Message); } finally { SystemTray.ProgressIndicator.IsVisible = false; } LoadDealsFromWallet(); }
protected override void GetSource( Envelope extent, int width, int height, DynamicLayer.OnImageComplete onComplete ) { _currentWidth = width; _currentHeight = height; MapPoints = new List<MapPoint>(); //Make up some dummy data int count = 0; while( count < 1000 ) { MapPoints.Add( new MapPoint( extent.XMin + ( extent.Width * ( _random.Next( 100 ) / 100.00 ) ), extent.YMin + ( extent.Height * ( _random.Next( 100 ) / 100.00 ) ), extent.SpatialReference ) ); count++; } //Make up some dummy data _pngRenderer = new PixelPngRenderer( _currentWidth, _currentHeight, MapPoints ); ParameterizedThreadStart starter = new ParameterizedThreadStart( ( pngRenderer ) => { Stream imageStream = InitalizeImage( pngRenderer as PixelPngRenderer ); Dispatcher.BeginInvoke( () => { _image = new BitmapImage(); _image.SetSource( imageStream ); onComplete( _image, width, height, extent ); } ); } ); new Thread( starter ).Start( _pngRenderer ); }
public EditPage() { InitializeComponent(); BitmapImage bi = new BitmapImage(); using (var store = IsolatedStorageFile.GetUserStoreForApplication()) { /*var filestream = store.OpenFile("image.jpg", System.IO.FileMode.Open, System.IO.FileAccess.Read); var imageAsBitmap = Microsoft.Phone.PictureDecoder.DecodeJpeg(filestream); image2.Source = imageAsBitmap; */ if (store.FileExists("tempJPEG2")) { using (IsolatedStorageFileStream fileStream = store.OpenFile("tempJPEG2", System.IO.FileMode.Open, System.IO.FileAccess.Read)) { bi.SetSource(fileStream); image2.Source = bi; } } else { var filestream = store.OpenFile("image.jpg", System.IO.FileMode.Open, System.IO.FileAccess.Read); var imageAsBitmap = Microsoft.Phone.PictureDecoder.DecodeJpeg(filestream); image2.Source = imageAsBitmap; } } }
private void SetImage(int index) { var refPic = App.ViewModel.Pictures[index].Id; var bitmap = new BitmapImage(); bitmap.SetSource(refPic.GetImage()); FullPicture.Source = bitmap; }
public MaskedBitmapImage(Stream selectedImage, String relativeUrl) { BitmapImage source = new BitmapImage(); source.SetSource(selectedImage); this.source = source; ChangeMask(relativeUrl); }
void ColorClient_FrameReady(object sender, FrameReadyEventArgs e) { MemoryStream ms = new MemoryStream(e.Data); BinaryReader br = new BinaryReader(ms); ColorFrameReadyEventArgs args = new ColorFrameReadyEventArgs(); ColorFrameData cfd = new ColorFrameData { Format = (ImageFormat)br.ReadInt32(), ImageFrame = br.ReadColorImageFrame() }; if(cfd.Format == ImageFormat.Raw) cfd.RawImage = br.ReadBytes(e.Data.Length - sizeof(bool)); else { BitmapImage bi = new BitmapImage(); bi.SetSource(new MemoryStream(e.Data, (int)ms.Position, (int)(ms.Length - ms.Position))); cfd.BitmapImage = bi; } ColorFrame = cfd; args.ColorFrame = cfd; if(ColorFrameReady != null) ColorFrameReady(this, args); }
public EditorPage() { InitializeComponent(); if (DataSystem.ChosenPhoto != null) { BitmapImage bitmapImagePreview = new BitmapImage(); bitmapImagePreview.SetSource(DataSystem.ChosenPhotoPreview); DataSystem.RenderedPreview = new WriteableBitmap(bitmapImagePreview); imgMain.Source = DataSystem.RenderedPreview; foreach (String effStr in _effStrList) { EffectElement t = new EffectElement(); t.SetEffectString(effStr); t.UpdateEffectImage(); effList.Children.Add(t); } DataSystem.RenderedPreview = new WriteableBitmap(bitmapImagePreview.PixelWidth, bitmapImagePreview.PixelHeight); BitmapImage bitmapImageThumbnail = new BitmapImage(); bitmapImageThumbnail.SetSource(DataSystem.ChosenPhotoThumbnailOrigin); DataSystem.RenderedThumbnail = new WriteableBitmap(bitmapImageThumbnail.PixelWidth, bitmapImageThumbnail.PixelHeight); } }
protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); StackPanel grid = (LayoutRoot.FindName("PhotoViewer") as StackPanel); using (IsolatedStorageFile isStore = IsolatedStorageFile.GetUserStoreForApplication()) { if(isStore.DirectoryExists("files")) { string[] fileNames = isStore.GetFileNames("files/*.jpg"); foreach (string fileName in fileNames) { // TextBlock block = new TextBlock(); // block.Text = fileName; // grid.Children.Add(block); Button button = new Button(); button.Content = fileName; button.VerticalContentAlignment = System.Windows.VerticalAlignment.Bottom; ImageBrush brush = new ImageBrush(); BitmapImage bi = new BitmapImage(); bi.SetSource(isStore.OpenFile("files\\"+fileName, FileMode.Open, FileAccess.Read)); brush.ImageSource = bi; brush.Stretch = Stretch.Uniform; button.Height = 300; button.Width = 300; button.Background = brush; grid.Children.Add(button); } } } }
/// <summary> /// Get an embedded resource image from the assembly. /// </summary> /// <param name="prefix">The prefix of the full name of the resource.</param> /// <param name="name">Name of the image resource.</param> /// <returns> /// Desired embedded resource image from the assembly. /// </returns> public static Image CreateImage(string prefix, string name) { Image image = new Image { Tag = name }; BitmapImage source = null; string resourceName = prefix + name; if (!cachedBitmapImages.TryGetValue(resourceName, out source)) { Assembly assembly = typeof(SharedResources).Assembly; using (Stream resource = assembly.GetManifestResourceStream(resourceName)) { if (resource != null) { source = new BitmapImage(); #if SILVERLIGHT source.SetSource(resource); #else source.StreamSource = resource; #endif } } cachedBitmapImages[resourceName] = source; } image.Source = source; return image; }
private void PopulateImageGrid() { MediaLibrary mediaLibrary = new MediaLibrary(); var pictures = mediaLibrary.Pictures; for (int i = 0; i < pictures.Count; i += Utilities.ImagesPerRow) { RowDefinition rd = new RowDefinition(); rd.Height = new GridLength(Utilities.GridRowHeight); grid1.RowDefinitions.Add(rd); int maxPhotosToProcess = (i + Utilities.ImagesPerRow < pictures.Count ? i + Utilities.ImagesPerRow : pictures.Count); int rowNumber = i / Utilities.ImagesPerRow; for (int j = i; j < maxPhotosToProcess; j++) { BitmapImage image = new BitmapImage(); image.SetSource(pictures[j].GetImage()); Image img = new Image(); img.Height = Utilities.ImageHeight; img.Stretch = Stretch.Fill; img.Width = Utilities.ImageWidth; img.HorizontalAlignment = HorizontalAlignment.Center; img.VerticalAlignment = VerticalAlignment.Center; img.Source = image; img.SetValue(Grid.RowProperty, rowNumber); img.SetValue(Grid.ColumnProperty, j - i); img.Tap += Image_Tap; grid1.Children.Add(img); } } }
public static ImageSource getImgFromByte(byte[] arrayImg) { BitmapImage bmpImage = new BitmapImage(); bmpImage.SetSource(new MemoryStream(arrayImg)); return bmpImage; }
/// <summary> /// cargar imagen de perfil. IsolatedSetting. /// </summary> private void foo() { // cargar la imagen del perfil try { if (true) { byte[] imageBytes = Convert.FromBase64String(ProfilePage.appSettings["image"].ToString()); MemoryStream ms = new MemoryStream(imageBytes); BitmapImage bitmapimage = new BitmapImage(); bitmapimage.SetSource(ms); Imagen.Source = bitmapimage; } } catch (Exception) { Imagen.Source = new BitmapImage(new Uri("/Images/naomi.jpg", UriKind.Relative)); } ntbx = ""; sntbx = ""; sntbx2 = ""; emtbx = ""; pntbx = ""; usrnameBox = ""; passBox = ""; }
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e) { if (a != null) { textBox1.Text = string.Format("这个有意思 →_→【{0}】{1}(分享自 @果壳网)", a.title, a.wwwurl); if (!string.IsNullOrEmpty(a.pic)) { string large_pic_uri = a.pic.Replace("/img2.", "/img1.").Replace("thumbnail", "gkimage").Replace("_90", ""); var large_uri = new Uri(large_pic_uri, UriKind.Absolute); var _imgsrc = new BitmapImage(); WebClient wc = new WebClient(); wc.Headers["Referer"] = "http://www.guokr.com"; wc.OpenReadCompleted += (s, ee) => { try { _imgsrc.SetSource(ee.Result); } catch { } }; wc.OpenReadAsync(large_uri); _imgsrc.ImageFailed += (ss, ee) => _imgsrc.UriSource = new Uri(a.pic, UriKind.Absolute); image_preview.Source = _imgsrc; } } sending_popup.Visibility = System.Windows.Visibility.Collapsed; }
void cct_Completed(object sender, PhotoResult e) { BitmapImage bi = new BitmapImage(); bi.SetSource(e.ChosenPhoto); SaveImage(bi); PageSource.InvokeScript("getImage", "pic.jpg"); }
public async Task<BitmapImage> GetImage(string url, bool go = false) { byte[] imageBytes = null; try { var httpClient = new HttpClient(); var response = await httpClient.GetAsync(url); response.EnsureSuccessStatusCode(); using (var stream = await response.Content.ReadAsStreamAsync()) { imageBytes = new byte[stream.Length]; stream.Read(imageBytes, 0, imageBytes.Length); } var imageStream = new MemoryStream(imageBytes); BitmapImage image = new BitmapImage(); image.SetSource(imageStream); return image; } catch (HttpRequestException ex) { return null; } }
public BitmapImage ImageFromBuffer(Byte[] bytes) { MemoryStream stream = new MemoryStream(bytes); BitmapImage image = new BitmapImage(); image.SetSource(stream); return image; }
void TaskToChoosePhoto_Completed(object sender, PhotoResult e) { if (e.TaskResult == TaskResult.OK) { string fileName = e.OriginalFileName; System.Windows.Media.Imaging.BitmapImage bmp = new System.Windows.Media.Imaging.BitmapImage(); bmp.SetSource(e.ChosenPhoto); Image_Selected.Source = bmp; _selectedPhotoStream = e.ChosenPhoto; } }
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { var photo = new System.Windows.Media.Imaging.BitmapImage(); byte[] bytes = System.Convert.FromBase64String((string)value); using (var stream = new System.IO.MemoryStream(bytes)) { photo.SetSource(stream); return(photo); } }
void photoChooserTask_Completed(object sender, PhotoResult e) { if (e.TaskResult == TaskResult.OK) { System.Windows.Media.Imaging.BitmapImage bmp = new System.Windows.Media.Imaging.BitmapImage(); bmp.SetSource(e.ChosenPhoto); this.CustomBackground.Source = bmp; ((App)App.Current).SaveCustomBackground(bmp); } }
private void photoChooserTask_Completed(object sender, PhotoResult e) { if (e.TaskResult == TaskResult.OK) { BitmapImage ChosenImage; ChosenImage = new System.Windows.Media.Imaging.BitmapImage(); ChosenImage.SetSource(e.ChosenPhoto); imgTakenPicture.Source = ChosenImage; btnSavePicture.IsEnabled = true; } }
void photoChooserTask_Completed(object sender, PhotoResult e) { if (e.TaskResult == TaskResult.OK) { MessageBox.Show(e.ChosenPhoto.Length.ToString()); //Code to display the photo on the page in an image control named myImage. System.Windows.Media.Imaging.BitmapImage bmp = new System.Windows.Media.Imaging.BitmapImage(); bmp.SetSource(e.ChosenPhoto); Chosen_Image.Source = bmp; image = bmp; imageStream = e.ChosenPhoto; imageName = e.OriginalFileName; imageStatus = true; } }
void cameraCaptureTask_Completed(object sender, PhotoResult e) { if (e.TaskResult == TaskResult.OK) { //MessageBox.Show(e.ChosenPhoto.Length.ToString()); //Code to display the photo on the page in an image control named myImage. System.Windows.Media.Imaging.BitmapImage bmp = new System.Windows.Media.Imaging.BitmapImage(); bmp.SetSource(e.ChosenPhoto); myImage.Source = bmp; myImage.Tap += new EventHandler <GestureEventArgs>(onImageTap); var todoItem = new allimages { username = uname }; InsertTodoItem(todoItem); } }
private void SetupDropTab(Task <Stream> photoResult) { var photo = photoResult.Result; if (photo != null) { DateTime creationDate = GetCreationDate(photo); Deployment.Current.Dispatcher.BeginInvoke(() => { var bmp = new System.Windows.Media.Imaging.BitmapImage(); bmp.SetSource(photo); PreviewImage.Source = bmp; Prefix.Text = creationDate.ToString("yyyy-MM-dd_HH.mm_"); }); } }
private void photoChooserTask_Completed(object sender, PhotoResult e) { // Get back the last PhotoInfo in the collection, which we just added. currentPhoto = App.ViewModel.Photos[App.ViewModel.Photos.Count - 1]; if (e.TaskResult == TaskResult.OK) { // Set the file properties for the returned image. string[] splitFileName = e.OriginalFileName.Split(new Char[] { '\\' }); currentPhoto.FileName = splitFileName[splitFileName.Length - 1]; currentPhoto.ContentType = GetContentTypeFromFileName(currentPhoto.FileName); // Read remaining entity properties from the stream itself. currentPhoto.FileSize = (int)e.ChosenPhoto.Length; // Create a new image using the returned memory stream. BitmapImage imageFromStream = new System.Windows.Media.Imaging.BitmapImage(); imageFromStream.SetSource(e.ChosenPhoto); // Set the height and width of the image. currentPhoto.Dimensions.Height = (short?)imageFromStream.PixelHeight; currentPhoto.Dimensions.Width = (short?)imageFromStream.PixelWidth; this.PhotoImage.Source = imageFromStream; // Reset the stream before we pass it to the service. e.ChosenPhoto.Position = 0; // Set the save stream for the selected photo stream. App.ViewModel.SetSaveStream(currentPhoto, e.ChosenPhoto, true, currentPhoto.ContentType, currentPhoto.FileName); } else { // Assume that the select photo operation was cancelled, // remove the added PhotoInfo and navigate back to the main page. App.ViewModel.Photos.Remove(currentPhoto); chooserCancelled = true; } }
private void AfficherImage(System.IO.MemoryStream pFileStream) { try { if (pFileStream != null) { var bmp = new System.Windows.Media.Imaging.BitmapImage(); bmp.SetSource(pFileStream); image.Source = bmp; if (_modeExecution == SessionObject.ExecMode.Consultation) { OKButton.Visibility = Visibility.Collapsed; CancelButton.Content = "Fermer"; } } } catch (Exception ex) { throw ex; } }
private async void postImgur(object sender, PhotoResult e) { string base64String = ""; string baseUrl = "https://api.imgur.com/3/upload.xml"; HttpClient browser = new HttpClient(); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, baseUrl); HttpResponseMessage result = new HttpResponseMessage(System.Net.HttpStatusCode.InternalServerError); if (e.TaskResult == TaskResult.OK) { updateTitleBar(AppResources.UploadingText); System.Windows.Media.Imaging.BitmapImage bmp = new System.Windows.Media.Imaging.BitmapImage(); bmp.SetSource(e.ChosenPhoto); byte[] bytearray = null; using (var ms = new System.IO.MemoryStream()) { if (bmp != null) { var wbitmp = new WriteableBitmap((BitmapImage)bmp); wbitmp.SaveJpeg(ms, bmp.PixelWidth, bmp.PixelHeight, 0, 85); bytearray = ms.ToArray(); } } if (bytearray != null) { base64String = Convert.ToBase64String(bytearray); } else { Debug.WriteLine("bytearray was null"); } request.Content = new StringContent(base64String); request.Headers.Add("Authorization", "Client-ID " + AppResources.ImgurApiKey); //make request try { //make request Task <HttpResponseMessage> resultTask = browser.SendAsync(request); result = await resultTask; } catch { updateTitleBar(); return; } Debug.WriteLine("Response: {0}", result.Content.ReadAsStringAsync().Result); System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex("<link>(.+?)</link>"); System.Text.RegularExpressions.Match match = reg.Match(result.Content.ReadAsStringAsync().Result); string url = match.ToString().Replace("<link>", "").Replace("</link>", ""); if (messageEntryBox.Text.Length > 0) { messageEntryBox.Text += url; } else { messageEntryBox.Text = url; } //nearly identical regexes :( fix reg = new System.Text.RegularExpressions.Regex("<id>(.+?)</id>"); match = reg.Match(result.Content.ReadAsStringAsync().Result); string id = match.ToString().Replace("<id>", "").Replace("</id>", ""); reg = new System.Text.RegularExpressions.Regex("<deletehash>(.+?)</deletehash>"); match = reg.Match(result.Content.ReadAsStringAsync().Result); string dh = match.ToString().Replace("<deletehash>", "").Replace("</deletehash>", ""); imageList.Add(new ImgurImage(id, url, dh)); appSettings["images"] = imageList; appSettings.Save(); updateTitleBar(); return; } }
public System.Windows.Media.Imaging.BitmapSource GetAvatarImage(string strHash) { System.Windows.Media.Imaging.BitmapImage objImage = null; IsolatedStorageFile storage = null; #if WINDOWS_PHONE storage = IsolatedStorageFile.GetUserStoreForApplication(); #else storage = IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Domain | IsolatedStorageScope.Assembly, null, null); #endif string strFileName = string.Format("{0}/{1}", AccountFolder, strHash); if (storage.FileExists(strFileName) == false) { storage.Dispose(); return(null); } IsolatedStorageFileStream stream = null; try { stream = new IsolatedStorageFileStream(strFileName, System.IO.FileMode.Open, storage); #if WINDOWS_PHONE objImage = new System.Windows.Media.Imaging.BitmapImage(); objImage.SetSource(stream); #else byte[] bData = new byte[stream.Length]; stream.Read(bData, 0, bData.Length); MemoryStream memstream = new MemoryStream(bData); //JpegBitmapDecoder decoder = new JpegBitmapDecoder(memstream, BitmapCreateOptions.None, BitmapCacheOption.OnLoad); //BitmapFrame frame = decoder.Frames[0]; //objImage = frame; objImage = new System.Windows.Media.Imaging.BitmapImage(); objImage.BeginInit(); objImage.CacheOption = System.Windows.Media.Imaging.BitmapCacheOption.OnLoad; objImage.CreateOptions = System.Windows.Media.Imaging.BitmapCreateOptions.None; objImage.StreamSource = memstream; objImage.EndInit(); double nWidth = objImage.Width; double nHeight = objImage.Height; #endif } catch (Exception ex) { System.Threading.Thread.Sleep(0); } finally { if (stream != null) { stream.Close(); } storage.Dispose(); } return(objImage); }
void timer_Tick(object sender, EventArgs e) { var cont = Application.Current.Host.Content; LockScreenSnapshot newLockInfo = new LockScreenSnapshot((int)Math.Ceiling(cont.ActualWidth * cont.ScaleFactor / 100.0), (int)Math.Ceiling(cont.ActualHeight * cont.ScaleFactor / 100.0)); if (LockInfoChanged(lockInfo, newLockInfo)) { lockInfo = newLockInfo; //Badges if (lockInfo.HasTrayBadges) { grdBadges.Visibility = System.Windows.Visibility.Visible; for (int i = 0; i < 5; i++) { if (!String.IsNullOrEmpty(lockInfo.Badges[i].BadgeValue)) { System.Windows.Media.Imaging.BitmapImage badge = new System.Windows.Media.Imaging.BitmapImage(); try { if (lockInfo.Badges[i].BadgeIcon != null) { badge.SetSource(new MemoryStream(lockInfo.Badges[i].BadgeIcon)); } else { var str = lockInfo.Badges[i].BadgeIconURI.Substring(7); badge.SetSource(new FileStream(lockInfo.Badges[i].BadgeIconURI.Substring(7), FileMode.Open)); } } catch { badge.UriSource = new Uri("ms-appx:///Assets/BadgeLogo.png", UriKind.Absolute); } imgBadges[i].Source = badge; txtBadges[i].Text = lockInfo.Badges[i].BadgeValue; imgBadges[i].Visibility = System.Windows.Visibility.Visible; txtBadges[i].Visibility = System.Windows.Visibility.Visible; } else { imgBadges[i].Visibility = System.Windows.Visibility.Collapsed; txtBadges[i].Visibility = System.Windows.Visibility.Collapsed; } } } else { grdBadges.Visibility = System.Windows.Visibility.Collapsed; } //Detailed texts for (int i = 0; i < lockInfo.DetailedTexts.Count(); i++) { if (!String.IsNullOrEmpty(lockInfo.DetailedTexts[i].Text)) { txtDetailedTexts[i].Text = lockInfo.DetailedTexts[i].Text; txtDetailedTexts[i].FontWeight = (lockInfo.DetailedTexts[i].IsBold) ? FontWeights.Bold : FontWeights.Normal; txtDetailedTexts[i].Visibility = System.Windows.Visibility.Visible; } else { txtDetailedTexts[i].Visibility = System.Windows.Visibility.Collapsed; } } } string[] TimeAMPM = DateTime.Now.ToShortTimeString().Split(space, 2, StringSplitOptions.RemoveEmptyEntries); HourText.Text = TimeAMPM[0]; AMPM.Text = TimeAMPM.Count() > 1 ? TimeAMPM[1] : ""; DatePanel.Text = DateTime.Now.ToShortDateString(); //Alarm BitmapImage alarmBadge = new BitmapImage(); if (lockInfo.AlarmIcon.BadgeIcon != null) { try { alarmBadge.SetSource(new MemoryStream(lockInfo.AlarmIcon.BadgeIcon)); } catch { alarmBadge.UriSource = new Uri("ms-appx:///Assets/BadgeLogo.png", UriKind.Absolute); } AlarmImage.Source = alarmBadge; } else { AlarmImage.Source = null; } FrameworkDispatcher.Update(); }