public async void LoadImage(String filename)
        {
            var file = await KnownFolders.PicturesLibrary.GetFileAsync(filename);

            ExtendedImage image = new ExtendedImage();
            image.LoadingCompleted +=
                (o, ea) => Dispatcher.BeginInvoke(() => { AnimatedImage.Source = image; });
            image.SetSource((await file.OpenReadAsync()).AsStreamForRead());
        }
        private async void LoadGifs()
        {
            StorageFile deleteFile = await Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Images/TaskDeleteAnimation.gif", UriKind.RelativeOrAbsolute));
            ExtendedImage delteImage = new ExtendedImage();
            delteImage.SetSource(await deleteFile.OpenStreamForReadAsync());
            this.TaskDeleteAnimation.Source = delteImage;

            StorageFile completeFile = await Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Images/TaskCompleteAnimation.gif", UriKind.RelativeOrAbsolute));
            ExtendedImage completeImage = new ExtendedImage();
            completeImage.SetSource(await completeFile.OpenStreamForReadAsync());
            this.TaskCompleteAnimation.Source = completeImage;
        }
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            if (NavigationContext.QueryString.TryGetValue("imageUri", out imageFileName))
            {
                FilenameText.Text = imageFileName;

                using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(imageFileName, System.IO.FileMode.Open, IsolatedStorageFile.GetUserStoreForApplication()))
                {
                    // Allocate an array large enough for the entire file
                    byte[] data = new byte[stream.Length];
                    // Read the entire file and then close it
                    stream.Read(data, 0, data.Length);
                    stream.Close();

                    ExtendedImage image = new ExtendedImage();
                    image.LoadingCompleted +=
                        (o, ea) => Dispatcher.BeginInvoke(() => { AnimatedImage.Source = image; });

                    image.SetSource(new MemoryStream(data));
                }
            }
        }
Example #4
0
		public override Codec.DecodeResult Decode( Stream input )
		{
			var wait = new ManualResetEvent( false );
			var its = new ExtendedImage();
			its.LoadingCompleted += ( s, e ) => wait.Set();
			its.LoadingFailed += ( s, e ) =>
									{
										Debug.WriteLine( e.ExceptionObject.ToString() );
										wait.Set();
									};
			its.SetSource( input );
			wait.WaitOne();
			return Decode( its );
		}
        public IEnumerable<IResult> LoadViewSignature()
        {
            if (this.IsLoadedSignature)
                yield break;

            // Initialize Objects here

            switch (AssistantMode) {
                case ViewMode.Add:
                    break;
                case ViewMode.Edit:
                    if (!string.IsNullOrWhiteSpace(this.User.Signature.Signature)) {
                        ExImage = new ExtendedImage();
                        ExImage.SetSource(new MemoryStream(System.Convert.FromBase64String(Security.AesDecrypt(this.User.Signature.Signature, SessionInfo.Instance.CurrentUser.BaseKey))));
                    }
                    break;
                default:
                    break;
            }

            UpdateSummarySignature();
            this.IsLoadedSignature = true;
        }
        public void LoadImage()
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.Multiselect = false;
            openFileDialog.Filter = "Image Files (*.jpg;*.png;*.bmp;*gif)|*.jpg;*.png;*.bmp;*.gif";
            if (openFileDialog.ShowDialog() == true) {

                FileInfo fileInfo = openFileDialog.File;
                exImage = new ExtendedImage();
                exImage.LoadingFailed += ExImageLoadingFailed;
                exImage.LoadingCompleted += ExImageOnLoadingCompleted;
                exImage.SetSource(fileInfo.OpenRead());
                //exImage.UriSource = new Uri(fileInfo.DirectoryName + "/erd.png", UriKind.Absolute);
            }
        }
		public static WriteableBitmap GetBitmapSource(byte[] data)
		{
			using (MemoryStream ms = new MemoryStream(data))
			{
				try
				{
					// Tries to load the image using Windows Phone's internals.
					BitmapImage image = null;
					image = new BitmapImage();
					image.SetSource(ms);

					return new WriteableBitmap(image);
				}
				catch (Exception)
				{
					try
					{
						// Resets the memory stream's position.
                        ms.Position = 0;

                        // It didn't work. Now try with ImageTools.
						ExtendedImage eim = new ExtendedImage();
						eim.SetSource(ms);

                        // Gets the image source for the image.
						WriteableBitmap bs = GetBitmapSource(eim);
                        if (bs == null)
                        {
                            // Something went wrong.
                            DebugUtils.DumpData(data, "ImageTools failed to generate an image source.");
                        }
                        return bs;
					}
					catch (Exception e)
					{
						// Dump data!
						DebugUtils.DumpData(data, e);
						return null;
					}
				}
			}
		}
Example #8
0
 private void SetImageSource(byte[] data)
 {
     Deployment.Current.Dispatcher.BeginInvoke(
         () =>
         {
             if (data == null)
                 return;
             #region jpeg/png
             try
             {
                 using (var memStream = new MemoryStream(data))
                 {
                     memStream.Position = 0;
                     var bitmapImage = new BitmapImage();
                     bitmapImage.SetSource(memStream);
                     ApplySource(bitmapImage);
                 }
             }
             #endregion
             #region others
             catch (Exception exception)
             {
                 Debug.WriteLine("set gif image. length: {0}", data.Length);
                 var memStream = new MemoryStream(data);
                 memStream.Position = 0;
                 var gifImage = new ExtendedImage();
                 gifImage.SetSource(memStream);
                 gifImage.LoadingCompleted += ExtendedImageLoadCompleted;
             }
             #endregion
         });
 }
        private void LoadImageFromStream(Stream imageStream, bool isCached = false)
        {
            bool imageLoaded = false;
            ImagePanel.Children.Clear();
            _bitmap = null;
            _imageControl = null;
            _extImageControl = null;

            if (_dupStream != null)
            {
                _dupStream.Close();
                _dupStream = null;
            }

            if (imageStream != null)
            {
                try
                {
                    Image imageControl = new System.Windows.Controls.Image();

                    _bitmap = new System.Windows.Media.Imaging.BitmapImage();
                    _bitmap.SetSource(imageStream);
                    imageControl.Source = _bitmap;
                    imageControl.DataContext = this;

                    if (_bitmap.PixelHeight > 0)
                    {
                        ImageHeight = _bitmap.PixelHeight;
                    }

                    if (_bitmap.PixelWidth > 0)
                    {
                        ImageWidth = _bitmap.PixelWidth;
                    }

                    imageControl.MaxHeight = MaxImageHeight;
                    imageControl.MaxWidth = MaxImageWidth;

                    imageControl.DataContext = this;

                    CreateButtons();

                    ImagePanel.Children.Add(imageControl);
                    _imageControl = imageControl;

                    if (HandlePinch)
                    {
                        AddGestureHandler(imageControl);
                    }

                    ImagePanel.Height = double.NaN;
                    imageLoaded = true;
                    ImageState = ImageStateType.Loaded;
                }
                catch (Exception)
                {
                    imageLoaded = false;
                    _bitmap = null;
                    _imageControl = null;
                }

                if (!imageLoaded && (imageStream.Length > 200))
                {
                    try
                    {
                        imageStream.Seek(0, System.IO.SeekOrigin.Begin);

                        _dupStream = new MemoryStream();

                        imageStream.CopyTo(_dupStream);
                        _dupStream.Seek(0, System.IO.SeekOrigin.Begin);

                        ImageTools.Controls.AnimatedImage extImageControl = new ImageTools.Controls.AnimatedImage();

                        ImageTools.ExtendedImage image = new ImageTools.ExtendedImage();
                        image.SetSource(_dupStream);
                        extImageControl.Source = image;
                        extImageControl.DataContext = this;

                        if (image.PixelHeight > 0)
                        {
                            ImageHeight = image.PixelHeight;
                        }

                        if (image.PixelWidth > 0)
                        {
                            ImageWidth = image.PixelWidth;
                        }

                        extImageControl.MaxHeight = MaxImageHeight;
                        extImageControl.MaxWidth = MaxImageWidth;

                        extImageControl.DataContext = this;

                        CreateButtons();

                        ImagePanel.Children.Add(extImageControl);
                        _extImageControl = extImageControl;

                        if (HandlePinch)
                        {
                            AddGestureHandler(extImageControl);
                        }

                        ImagePanel.Height = double.NaN;
                        imageLoaded = true;
                        ImageState = ImageStateType.Loaded;
                    }
                    catch (Exception)
                    {

                    }
                }
            }

            if (!imageLoaded)
            {
                if (isCached)
                {
                    imageStream.Close();
                    App.Settings.OfflineContentManager.CleanupOfflineContent(OfflineID, ImageUrl);

                    IsOffline = false;
                    ImageState = ImageStateType.Unloaded;
                    ShowManualLoad();

                    _web = null;

                    if (ImageItemLoaded != null)
                    {
                        ImageItemLoaded(this, null);
                    }
                }
                else
                {
                    ImageState = ImageStateType.Error;

                    if (ShowViewerLink)
                    {
                        ShowViewer();
                    }
                    else
                    {
                        ShowError();
                    }
                }
            }

            _web = null;

            if (ImageItemLoaded != null)
            {
                ImageItemLoaded(this, null);
            }

            if (imageLoaded && !isCached && imageStream != null && CacheImage)
            {
                imageStream.Seek(0, System.IO.SeekOrigin.Begin);
                App.Settings.OfflineContentManager.SaveOfflineContent(OfflineID, ImageUrl, imageStream);
            }
        }
Example #10
0
        private void UpdateImage()
        {
            if (SourceStream == null) return;
            SourceStream.Seek(0, SeekOrigin.Begin);

            try
            {
                if (IsGif)
                {
                    GifImage = new ExtendedImage();
                    GifImage.SetSource(SourceStream);
                }
                else
                {
                    Image = new BitmapImage();
                    Image.SetSource(SourceStream);
                    SourceStream.Dispose();
                    SourceStream = null;
                }
                OnImageOpened();
            }
            catch
            {
                Image = null;
                GifImage = null;
                if (!IsGif && IsEmotion)
                {
                    IsGif = !IsGif;
                    UpdateImage();
                }
                else
                    OnImageOpenFailed();
            }
        }