Exemplo n.º 1
0
 private void SetImageSource(string imageKey, BitmapSource imageSource, Stream imageDataStream)
 {
     if (imageSource == null)
     {
         throw new ArgumentNullException("imageSource");
     }
     try
     {
         imageSource.SetSource(imageDataStream);
     }
     catch (Exception)
     {
         DeleteImageFromCache(imageKey);
         DeleteImageFromMemoryCache(imageKey);
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Util: Dispose a bitmap resource
 /// </summary>
 /// <param name="image">BitmapSource subclass to dispose</param>
 private void DisposeImage(BitmapSource image)
 {
     if (image != null)
     {
         try
         {
             using (var ms = new MemoryStream(new byte[] { 0x0 }))
             {
                 image.SetSource(ms);
             }
         }
         catch (Exception)
         {
         }
     }
 }
Exemplo n.º 3
0
        void photoChooser_Completed(object sender, PhotoResult e)
        {
            if (e.Error != null || e.ChosenPhoto == null)//没有选择图片则返回跳出该方法
            {
                return;
            }
            //创建BitmapImage来存储选择器的图片

            if (IsFromPhoto == false)
            {
                BitmapImage bitmapImage = new BitmapImage();
                bitmapImage.SetSource(e.ChosenPhoto);
                Image imgBase = new Image();
                imgBase.Source = bitmapImage;

                WriteableBitmap writeableBitmap = new WriteableBitmap(480, 600);

                ScaleTransform scale = new ScaleTransform();
                scale.ScaleX = 480.0 / bitmapImage.PixelHeight;
                scale.ScaleY = 640.0 / bitmapImage.PixelWidth;

                RotateTransform rotate = new RotateTransform();
                rotate.Angle = 90;
                //rotate.CenterX = 4.0 / 2;
                //rotate.CenterY = 640.0 / 2;

                TranslateTransform translate = new TranslateTransform();
                translate.X = 480;
                //translate.Y = -60;

                TransformGroup transGroup = new TransformGroup();
                transGroup.Children.Add(scale);
                transGroup.Children.Add(rotate);
                transGroup.Children.Add(translate);

                writeableBitmap.Render(imgBase, transGroup);//在位图中呈现元素
                writeableBitmap.Invalidate();
                bitmapSource = writeableBitmap;
            }
            else
            {
                bitmapSource = new BitmapImage();
                bitmapSource.SetSource(e.ChosenPhoto);
            }
            //   this.NavigationService.Navigate(new Uri("/SecondPage.xaml", UriKind.Relative));
            Dispatcher.BeginInvoke(() =>
            {
                NavigationService.Navigate(new Uri("/GamePage.xaml", UriKind.Relative));
            });
        }