Ejemplo n.º 1
0
        private void btnSalvar_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string _tmpImage = "tmpImage";
                string _msgMensagem = "Imagem grava com sucesso!";

                var store = IsolatedStorageFile.GetUserStoreForApplication();
                if (store.FileExists(_tmpImage)) store.DeleteFile(_tmpImage);

                IsolatedStorageFileStream _stream = store.CreateFile(_tmpImage);
                WriteableBitmap _writeImage = new WriteableBitmap(_imagetmp);

                Extensions.SaveJpeg(_writeImage, _stream, _writeImage.PixelWidth,
                    _writeImage.PixelHeight, 0, 100);
                _stream.Close();
                _stream = store.OpenFile(_tmpImage, System.IO.FileMode.Open,
                    System.IO.FileAccess.Read);

                MediaLibrary _mlibrary = new MediaLibrary();
                _mlibrary.SavePicture(_stream.Name, _stream);
                _stream.Close();

                btnSalvar.IsEnabled = false;
                lblStatus.Text = _msgMensagem;
            }
            catch (Exception error)
            {
                lblStatus.Text = error.Message;
            }
        }
Ejemplo n.º 2
0
        public static Boolean capture(int quality)
        {
            try
            {
                PhoneApplicationFrame frame = (PhoneApplicationFrame)Application.Current.RootVisual;
                WriteableBitmap bitmap = new WriteableBitmap((int)frame.ActualWidth, (int)frame.ActualHeight);
                bitmap.Render(frame, null);
                bitmap.Invalidate();

                string fileName = DateTime.Now.ToString("'Capture'yyyyMMddHHmmssfff'.jpg'");
                IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication();
                if (storage.FileExists(fileName))
                    return false;

                IsolatedStorageFileStream stream = storage.CreateFile(fileName);
                bitmap.SaveJpeg(stream, bitmap.PixelWidth, bitmap.PixelHeight, 0, quality);
                stream.Close();

                stream = storage.OpenFile(fileName, FileMode.Open, FileAccess.Read);
                MediaLibrary mediaLibrary = new MediaLibrary();
                Picture picture = mediaLibrary.SavePicture(fileName, stream);
                stream.Close();

                storage.DeleteFile(fileName);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                return false;
            }

            return true;
        }
Ejemplo n.º 3
0
        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();
        }
Ejemplo n.º 4
0
    public void saveImageDataToLibrary(string jsonArgs)
    {
        try
        {
            var options = JsonHelper.Deserialize<string[]>(jsonArgs);

            string imageData = options[0];
            byte[] imageBytes = Convert.FromBase64String(imageData);

            using (var imageStream = new MemoryStream(imageBytes))
            {
                imageStream.Seek(0, SeekOrigin.Begin);

                string fileName = String.Format("c2i_{0:yyyyMMdd_HHmmss}", DateTime.Now);
                var library = new MediaLibrary();
                var picture = library.SavePicture(fileName, imageStream);

                if (picture.Name.Contains(fileName))
                {
                    DispatchCommandResult(new PluginResult(PluginResult.Status.OK,
                        "Image saved: " + picture.Name));
                }
                else
                {
                    DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR,
                        "Failed to save image: " + picture.Name));
                }
            }
        }
        catch (Exception ex)
        {
            DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, ex.Message));
        }
    }
Ejemplo n.º 5
0
 public static void SaveToPhotoLibrary(this Texture2D texture, string filename)
 {
     MemoryStream memoryStream = new MemoryStream();
     texture.SaveAsJpeg(memoryStream, texture.Width, texture.Height);
     memoryStream.Position = 0;
     MediaLibrary mediaLibrary = new MediaLibrary();
     mediaLibrary.SavePicture(filename, memoryStream);
     memoryStream.Close();
 }
Ejemplo n.º 6
0
        private void PreparePopups()
        {
            if (theHelpPopup == null)
            {
                theHelpPopup                  = new Popup();
                theHelpPopup.Child            = new HelpPopup();
                theHelpPopup.VerticalOffset   = 200;
                theHelpPopup.HorizontalOffset = 0;
                theHelpPopup.Closed          += (sender1, e1) =>
                {
                    this.ApplicationBar.IsVisible = true;
                };
            }
            if (theSavePopup == null)
            {
                theSavePopup                  = new Popup();
                theSavePopup.Child            = new HelpSavePopup();
                theSavePopup.VerticalOffset   = 70;
                theSavePopup.HorizontalOffset = 0;
                theSavePopup.Closed          += (sender1, e1) =>
                {
                    try
                    {
                        if (!backButtonPressedFlag)
                        {
                            var bitmap = new System.Windows.Media.Imaging.WriteableBitmap(this.LayoutRoot, null);
                            using (var stream = new System.IO.MemoryStream())
                            {
                                System.Windows.Media.Imaging.Extensions.SaveJpeg(bitmap, stream,
                                                                                 bitmap.PixelWidth, bitmap.PixelHeight, 0, 100);
                                stream.Position = 0;
                                var mediaLib = new Microsoft.Xna.Framework.Media.MediaLibrary();
                                var datetime = System.DateTime.Now;
                                var filename =
                                    System.String.Format("LockScreen-{0}-{1}-{2}-{3}-{4}",
                                                         datetime.Year % 100, datetime.Month, datetime.Day,
                                                         datetime.Hour, datetime.Minute);
                                mediaLib.SavePicture(filename, stream);

                                var toast = new ToastPrompt
                                {
                                    Title   = "Saved",
                                    Message = @"Your wallpaper is in ""Saved Pictures"""
                                };
                                toast.Show();
                            }
                        }
                        backButtonPressedFlag = false;
                    }
                    finally
                    {
                        UpdateMockup(false);
                    }
                };
            }
        }
Ejemplo n.º 7
0
 private void ButtonSaveFile_Click(object sender, RoutedEventArgs e)
 {
     FileTransfer trans = ((FrameworkElement)sender).DataContext as FileTransfer;
     if (trans != null)
     {
         var library = new MediaLibrary();
         library.SavePicture(trans.FileName, trans.Bytes);
         MessageBox.Show("File saved to 'Saved Pictures'", "File Saved", MessageBoxButton.OK);
     }
 }
Ejemplo n.º 8
0
        public void GeoTagAddition()
        {
            var task = WaitLocation();
            task.Wait();
            var position = task.Result;
            Debug.WriteLine("pos: " + position.Coordinate.Longitude + " " + position.Coordinate.Latitude);
            var mediaLibrary = new MediaLibrary();

            int count = 0;
            foreach (string filename in TestFiles.GeotagTargetImages)
            {
                var image = TestUtil.GetResourceByteArray(filename);
                var originalMetadata = JpegMetaDataParser.ParseImage(image);
                var NewImage = MetaDataOperator.AddGeoposition(image, position);
                var newMetadata = JpegMetaDataParser.ParseImage(NewImage);
                try
                {
                    var pic = mediaLibrary.SavePicture(string.Format("Exif addition test_" + count + "_{0:yyyyMMdd_HHmmss}.jpg", DateTime.Now), NewImage);
                }
                catch (NullReferenceException) { }

                TestUtil.IsGpsDataAdded(originalMetadata, newMetadata);

                using (var imageStream = TestUtil.GetResourceStream(filename))
                {
                    originalMetadata = JpegMetaDataParser.ParseImage(imageStream);
                    var newImageStream = MetaDataOperator.AddGeoposition(imageStream, position);
                    try
                    {
                        var pic2 = mediaLibrary.SavePicture(string.Format("Exif addition test_" + count + "_stream_{0:yyyyMMdd_HHmmss}.jpg", DateTime.Now), newImageStream);
                    }
                    catch (NullReferenceException) { }
                    finally { newImageStream.Close(); }

                    TestUtil.IsGpsDataAdded(originalMetadata, newMetadata);
                    imageStream.Close();
                    newImageStream.Close();
                    count++;
                }
                GC.Collect(); // Saving many big images in short time, memory mey be run out and it may throws NullReferenceException.
            }
        }
 private void SaveMergebtn_click(object sender, RoutedEventArgs e)
 {
     using (MemoryStream stream = new MemoryStream())
     {
         wb.SaveJpeg(stream, wb.PixelWidth, wb.PixelHeight, 0, 100);
         stream.Seek(0, SeekOrigin.Begin);
         using (MediaLibrary mediaLibrary = new MediaLibrary())
             mediaLibrary.SavePicture("Picture.jpg", stream);
     }
     MessageBox.Show("Picture Saved to media library...");
 }
 /// <summary>
 /// Saves the WriteableBitmap encoded as JPEG to the Media library.
 /// </summary>
 /// <param name="bitmap">The WriteableBitmap to save.</param>
 /// <param name="name">The name of the destination file.</param>
 /// <param name="quality">The quality for JPEG encoding has to be in the range 0-100, 
 /// where 100 is the best quality with the largest size.</param>
 /// <param name="saveToCameraRoll">If true the bitmap will be saved to the camera roll, otherwise it will be written to the default saved album.</param>
 public static Picture SaveToMediaLibrary(this WriteableBitmap bitmap, string name, int quality, bool saveToCameraRoll = false)
 {
    using (var stream = new MemoryStream())
    {
       // Save the picture to the WP media library
       bitmap.SaveJpeg(stream, bitmap.PixelWidth, bitmap.PixelHeight, 0, quality);
       stream.Seek(0, SeekOrigin.Begin);
       var mediaLibrary = new MediaLibrary();
       return saveToCameraRoll ? mediaLibrary.SavePictureToCameraRoll(name, stream) : mediaLibrary.SavePicture(name, stream);
    }
 }
 /// <summary>
 /// Salva a imagem na biblioteca de imagens
 /// </summary>
 private void Save_Click(object sender, RoutedEventArgs e)
 {
     MediaLibrary library = new MediaLibrary();
     WriteableBitmap bitMap = new WriteableBitmap(drawCanvas, null);
     MemoryStream ms = new MemoryStream();
     Extensions.SaveJpeg(bitMap, ms, bitMap.PixelWidth,
                         bitMap.PixelHeight, 0, 100);
     ms.Seek(0, SeekOrigin.Begin);
     library.SavePicture(string.Format("Images\\{0}.jpg",
                                        Guid.NewGuid()), ms);
     New_Click(sender, e);
 }
Ejemplo n.º 12
0
 private void Button_Click_2(object sender, RoutedEventArgs e)
 {
     WriteableBitmap writeableBitmap = new WriteableBitmap(480, 800);
     writeableBitmap.Render(App.Current.RootVisual, null);
     writeableBitmap.Invalidate();
     MemoryStream memoryStream = new MemoryStream();
     writeableBitmap.SaveJpeg(memoryStream, writeableBitmap.PixelWidth, writeableBitmap.PixelHeight,0, 100);
     memoryStream.Seek(0, SeekOrigin.Begin);
     MediaLibrary mediaLibrary = new MediaLibrary();
     mediaLibrary.SavePicture(Guid.NewGuid().ToString() + ".jpg", memoryStream);
     memoryStream.Close();
 }
Ejemplo n.º 13
0
 private void SaveButton_OnClick(object sender, EventArgs e)
 {
     if (!_canPress) return;
     string path = EditingLockscreenFilename + ".jpg";
     using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
     {
         var stream = storage.OpenFile(path, FileMode.Open);
         var library = new MediaLibrary();
         library.SavePicture("test", stream);
         stream.Close();
     }
 }
Ejemplo n.º 14
0
		private void btnSaveImage_Click (object sender, RoutedEventArgs e)
		{
			WriteableBitmap bitmap = signatureView.GetImage ();

			using (MemoryStream stream = new MemoryStream ()) {
				bitmap.SaveJpeg (stream, bitmap.PixelWidth, bitmap.PixelHeight, 0, 100);
				stream.Seek (0, SeekOrigin.Begin);

				using (MediaLibrary mediaLibrary = new MediaLibrary ())
					mediaLibrary.SavePicture ("signature.jpg", stream);
			}
			MessageBox.Show ("Picture saved to photo library");
		}
Ejemplo n.º 15
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            // Grid から Jpeg 保存用ストリームを作成
            WriteableBitmap wp = new WriteableBitmap(imgGrid, null);
            MemoryStream stream = new MemoryStream();
            wp.SaveJpeg(stream, wp.PixelWidth, wp.PixelHeight, 0, 100);

            // PictureHub に保存する
            using (MediaLibrary lib = new MediaLibrary()) {
                lib.SavePicture("PhotoEffect-" + DateTime.Now.ToString("yyyyMMddhhmmss"), stream.ToArray());
                MessageBox.Show("保存しました");
            }
        }
        // Constructor
        public PageMethod1()
        {
            InitializeComponent();

            CameraButtons.ShutterKeyPressed += (s, e) =>
            {
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    var bmp = new WriteableBitmap(displayImage, null);
                    var sout = new MemoryStream();
                    bmp.SaveJpeg(sout, bmp.PixelWidth, bmp.PixelHeight, 0, 70);
                    sout.Seek(0, SeekOrigin.Begin);

                    using (MediaLibrary mediaLibrary = new MediaLibrary())
                        mediaLibrary.SavePicture(String.Format("PictureNavigation Method1 {0:yyyyMMdd-HHmmss}", DateTime.Now), sout);
                });




            };


            Loaded += (s, e) =>
            {
                method.Output = displayImage;


                DispatcherTimer timer = new DispatcherTimer();
                timer.Tick += (ss, ee) =>
                {
                    const string total = "DeviceTotalMemory";
                    const string current = "ApplicationCurrentMemoryUsage";
                    const string peak = "ApplicationPeakMemoryUsage";

                    var currentBytes = ((long)DeviceExtendedProperties.GetValue(current)) / 1024.0 / 1024.0;


                    var txt = string.Format("Memory  = {0,5:F} MB / {1,5:F} MB\n", currentBytes, DeviceStatus.ApplicationMemoryUsageLimit / 1024 / 1024);
                    displayInfo.Text = txt + method.Info();




                };
                timer.Interval = new TimeSpan(0, 0, 0, 0, 40);
                timer.Start();


            };
        }
Ejemplo n.º 17
0
        private static void AddImages()
        {
            string[] fileNames = { "DomriRade" };
            foreach (var fileName in fileNames)
            {
                MediaLibrary myMediaLibrary = new MediaLibrary();
                Uri myUri = new Uri(String.Format(@"TestImages/{0}.jpg", fileName), UriKind.Relative);

                System.IO.Stream photoStream = App.GetResourceStream(myUri).Stream;
                byte[] buffer = new byte[photoStream.Length];
                photoStream.Read(buffer, 0, Convert.ToInt32(photoStream.Length));
                myMediaLibrary.SavePicture(String.Format("{0}.jpg", fileName), buffer);
                photoStream.Close();
            }
        }
Ejemplo n.º 18
0
        void TakePictureFromCameraCompleted(object sender, PhotoResult photoResult)
        {
            if (photoResult.TaskResult == TaskResult.OK && photoResult.ChosenPhoto != null)
            {
                Stream photoStream = photoResult.ChosenPhoto;
                BitmapImage imageFromCamera = new BitmapImage();
                imageFromCamera.SetSource(photoStream);
                mediaGallery.addImageToGallery(imageFromCamera);

                var mediaLibrary = new MediaLibrary();
                photoStream.Position = 0;
                mediaLibrary.SavePicture("photoBookImage" + numberOfAddedImages, photoStream);
                numberOfAddedImages++;
            }
        }
Ejemplo n.º 19
0
    /// <summary>
    /// Save bitmap to media library
    /// </summary>
    /// <param name="bmp"></param>
    public static Picture SaveBitmapToMediaLibrary(BitmapSource bmp)
    {
      const string FILENAME_PREFIX = "TapfishPhoto_";
      using (var stm = new MemoryStream())
      {
        var wbmp = new WriteableBitmap(bmp);
        Extensions.SaveJpeg(wbmp, stm, wbmp.PixelWidth, wbmp.PixelHeight, 0, 85);
        stm.Seek(0, SeekOrigin.Begin);

        var outputName = string.Concat(FILENAME_PREFIX, DateTime.Now.Ticks);
        var library = new MediaLibrary();
        var pic = library.SavePicture(outputName, stm);
        return pic;
      }
    }
Ejemplo n.º 20
0
        private void saveButton1_Click(object sender, RoutedEventArgs e)
        {
            var myStore = IsolatedStorageFile.GetUserStoreForApplication();
            IsolatedStorageFileStream myFileStream = myStore.CreateFile("tempJPEG");

            WriteableBitmap wb = new WriteableBitmap(ContentPanelCanvas, null);
            wb.SaveJpeg(myFileStream, 1000, 667, 0, 100);
            myFileStream.Close();

            myFileStream = myStore.OpenFile("tempJPEG", System.IO.FileMode.Open, System.IO.FileAccess.Read);
            MediaLibrary library = new MediaLibrary();
            Picture pic = library.SavePicture("NewPicture.jpg", myFileStream);
            MessageBox.Show("Image saved");
            myFileStream.Close();
        }
Ejemplo n.º 21
0
        public static void Save(UIElement elt)
        {
            var bmp = new WriteableBitmap(elt, null);
            var width = (int)bmp.PixelWidth;
            var height = (int)bmp.PixelHeight;
            using (var ms = new MemoryStream(width * height * 4))
            {
                Picture picture;
                bmp.SaveJpeg(ms, width, height, 0, 100);
                ms.Seek(0, SeekOrigin.Begin);
                var lib = new MediaLibrary();
                var name = String.Format("{0:yyyy-MM-dd_hh-mm-ss}.jpg", DateTime.Now);
                picture = lib.SavePicture(string.Format(name), ms);

            }
        }
Ejemplo n.º 22
0
        public static Picture Take(UIElement elt,String name)
        {
            var bmp = new WriteableBitmap(elt, null);
            var width = (int)bmp.PixelWidth;
            var height = (int)bmp.PixelHeight;
            using (var ms = new MemoryStream(width * height * 4))
            {
                Picture picture;

                bmp.SaveJpeg(ms, width, height, 0, 100);
                ms.Seek(0, SeekOrigin.Begin);
                var lib = new MediaLibrary();
                picture = lib.SavePicture(string.Format(name), ms);
                
                return picture;
            }
        }
Ejemplo n.º 23
0
 private void saveimage()
 {
     WriteableBitmap wBitmap = new WriteableBitmap(statistics, null);
     using (MemoryStream stream = new MemoryStream())
     {
         wBitmap.SaveJpeg(stream, (int)statistics.ActualWidth, (int)statistics.ActualHeight, 0, 100);
         wBitmap = null;
         //Use can either save the file to isolated storage or media library.
         //Creates file in Isolated Storage.
         using (var local = new IsolatedStorageFileStream("/Statistics", FileMode.Create, IsolatedStorageFile.GetUserStoreForApplication()))
         {
             local.Write(stream.GetBuffer(), 0, stream.GetBuffer().Length);
         }
         //Creates file in Media Library.
         var lib = new MediaLibrary();
         var picture = lib.SavePicture("Statistics", stream.GetBuffer());
     }
 }
Ejemplo n.º 24
0
        private void ApplicationBarIconButtonSave_Click(object sender, EventArgs e)
        {
            var wb = new WriteableBitmap(gridCard, new ScaleTransform { CenterX = 0, CenterY = 0, ScaleX = 2, ScaleY = 2 });
            var iso = IsolatedStorageFile.GetUserStoreForApplication();
            using (var fs = iso.OpenFile("tmp.jpg", FileMode.Create))
            {
                wb.SaveJpeg(fs, 800, 400, 0, 100);
            }

            var library = new MediaLibrary();
            var fileName = string.Format("twitterCard{0:yyyyMMddHHmmss}.jpg", DateTime.Now);
            using (var fs = iso.OpenFile("tmp.jpg", FileMode.Open))
            {
                library.SavePicture(fileName, fs);
            }

            MessageBox.Show(string.Format("名刺を{0}という名前で保存しました", fileName));
        }
Ejemplo n.º 25
0
        private void Save_Click(object sender, RoutedEventArgs e)
        {
            IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
            int imageNumber = 0;
            settings.TryGetValue<int>("PreviousImageNumber", out imageNumber);
            imageNumber++;

            MediaLibrary library = new MediaLibrary();
            WriteableBitmap wbmp = new WriteableBitmap(canvas1,null);

            MemoryStream ms = new MemoryStream();
            Extensions.SaveJpeg(wbmp, ms, wbmp.PixelWidth, wbmp.PixelHeight, 0, 100);
            ms.Seek(0, SeekOrigin.Begin);
            library.SavePicture(string.Format("Images\\{0}.jpg", imageNumber), ms);

            settings["PreviousImageNumber"] = imageNumber;
            settings.Save();
        }
Ejemplo n.º 26
0
 private void ApplicationBarIconButton_Click(object sender, EventArgs e)
 {
     String url = App.ViewModel.PictureItems[m_nIndex].FullUrl;
     WebClient client = new WebClient();
     client.OpenReadCompleted += (s, e1) =>
     {
         if (e1.Error == null)
         {
             MediaLibrary library = new MediaLibrary();
             library.SavePicture("Image_From_Care", e1.Result);
             Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                MessageBox.Show("保存成功");
            });
         }
     };
     client.OpenReadAsync(new Uri(url, UriKind.Absolute));
 }
Ejemplo n.º 27
0
        ///////////////////////////////////////////////////////
        // 【処理3】 画像保存
        ///////////////////////////////////////////////////////
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (imgPhoto.Source == null)
            {
                MessageBox.Show("先に画像を選んでください");
                return;
            }
            ////⑥画像保存処理
            ////Grid から Jpeg 保存用ストリームを作成
            WriteableBitmap wp = new WriteableBitmap(PictureFrame, null);
            MemoryStream stream = new MemoryStream();
            wp.SaveJpeg(stream, wp.PixelWidth, wp.PixelHeight, 0, 100);

            ////PictureHub に保存する
            using (MediaLibrary lib = new MediaLibrary())
            {
                lib.SavePicture("PhotoEffectEx", stream.ToArray());
                MessageBox.Show("保存しました");
            }
        }
Ejemplo n.º 28
0
        private void save(object sender, System.EventArgs e)
        {
            String tempJPEG = "TempJPEG";
            var myStore = IsolatedStorageFile.GetUserStoreForApplication();
            if (myStore.FileExists(tempJPEG))
                myStore.DeleteFile(tempJPEG);
            IsolatedStorageFileStream myFileStream = myStore.CreateFile(tempJPEG);
            WriteableBitmap wb = new WriteableBitmap(imageGrid, new ScaleTransform());
            wb.SaveJpeg(myFileStream, wb.PixelWidth, wb.PixelHeight, 0, 85);
            myFileStream.Close();
            myFileStream = myStore.OpenFile(tempJPEG, FileMode.Open, FileAccess.Read);

            MediaLibrary library = new MediaLibrary();

            Picture pic = library.SavePicture("LeMeme-" + DateTime.Now.ToString(), myFileStream);
            MessageBox.Show("Image saved to saved pictures album");

            myFileStream.Close();
            NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.RelativeOrAbsolute));
        }
Ejemplo n.º 29
0
 private void saveImage(object sender, EventArgs e)
 {
     String tempJPEG = "TempJPEG";
     IsolatedStorageFile myStore = IsolatedStorageFile.GetUserStoreForApplication();
     if (myStore.FileExists(tempJPEG))
     {
         myStore.DeleteFile(tempJPEG);
     }
     IsolatedStorageFileStream myFileStream = myStore.CreateFile(tempJPEG);
     var bitmap = new WriteableBitmap(img, new ScaleTransform());
     bitmap.SaveJpeg(myFileStream, bitmap.PixelWidth, bitmap.PixelHeight, 0, 85);
     myFileStream.Close();
     myFileStream = myStore.OpenFile(tempJPEG, FileMode.Open, FileAccess.Read);
     var library = new MediaLibrary();
     string name = instance.CurrentImage.Substring(instance.CurrentImage.LastIndexOf('/') + 1);
     name = name.Split('.')[0];
     Picture pic = library.SavePicture(name, myFileStream);
     MessageBox.Show("Image saved to saved pictures album");
     myFileStream.Close();
     NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.RelativeOrAbsolute));
 }
Ejemplo n.º 30
0
        private void Button_Click_3(object sender, RoutedEventArgs e)
        {
            RectangleGeometry rectangleGeometry = new RectangleGeometry();
            rectangleGeometry.Rect = new Rect(0, 0, 50, 50);
            image1.Clip = rectangleGeometry;

            WriteableBitmap writeableBitmaptemp = new WriteableBitmap(image1, null);

            Image image = new Image();
            image.Stretch = Stretch.None;
            image.Height = 50;
            image.Width = 50;
            image.Source = writeableBitmaptemp;

            WriteableBitmap writeableBitmap = new WriteableBitmap(image, null);
            MemoryStream memoryStream = new MemoryStream();
            writeableBitmap.SaveJpeg(memoryStream, writeableBitmap.PixelWidth, writeableBitmap.PixelHeight, 0, 100);
            memoryStream.Seek(0, SeekOrigin.Begin);
            MediaLibrary mediaLibrary = new MediaLibrary();
            mediaLibrary.SavePicture(Guid.NewGuid().ToString() + ".jpg", memoryStream);
            memoryStream.Close();
        }
Ejemplo n.º 31
0
        /// <summary>
        /// Saves an image sent or received in the media library of the device.
        /// </summary>
        /// <param name="fileName">File's name in the isolated storage</param>
        /// <returns>true if the operation succeeds</returns>
        public static bool SavePictureInMediaLibrary(string fileName)
        {
            MediaLibrary library = new MediaLibrary();
            byte[] data;
            try
            {
                using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    using (IsolatedStorageFileStream file = store.OpenFile(fileName, FileMode.Open, FileAccess.Read))
                    {
                        data = new byte[file.Length];
                        file.Read(data, 0, data.Length);
                        file.Close();
                    }
                }

                library.SavePicture(fileName, data);
                return true;
            }
            catch { }
            return false;
        }