Created
February 21, 2015 05:11
-
-
Save arn-ob/1925d5e1f5e55664e885 to your computer and use it in GitHub Desktop.
Take a image one xaml page to another xaml page at win phone 8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Net; | |
using System.Windows; | |
using System.Windows.Controls; | |
using System.Windows.Navigation; | |
using Microsoft.Phone.Controls; | |
using Microsoft.Phone.Shell; | |
using PhotoChoose.Resources; | |
using Microsoft.Phone.Tasks; | |
using System.IO.IsolatedStorage; | |
using System.Windows.Media.Imaging; | |
using System.IO; | |
namespace PhotoChoose | |
{ | |
// This can take image and store the image :D | |
// browes that image and store it in a image box .. | |
// xaml image tag must be take to out of the grid ..... | |
// it send that image to the other page | |
/// <summary> | |
/// xaml code | |
/// <Button Content="Go to page 2" HorizontalAlignment="Left" Margin="111,412,0,0" VerticalAlignment="Top" Click="ToPage2Button_Click" Width="204" /> | |
/// <Button Content="PhotoChooser" HorizontalAlignment="Left" Margin="118,321,0,0" VerticalAlignment="Top" Click="LoadButton_Click"/> | |
/// <Image x:Name="PageImage" HorizontalAlignment="Left" Height="180" Margin="67,60,0,0" VerticalAlignment="Top" Width="344" Grid.Row="1"/> | |
/// </summary> | |
public partial class MainPage : PhoneApplicationPage | |
{ | |
// Constructor | |
PhotoChooserTask PhotoChooser; | |
int ImageWidth, ImageHeight; | |
// Constructor | |
public MainPage() | |
{ | |
InitializeComponent(); | |
ImageWidth = (int)PageImage.Width; | |
ImageHeight = (int)PageImage.Height; | |
PhotoChooser = new PhotoChooserTask(); | |
PhotoChooser.PixelWidth = ImageWidth; | |
PhotoChooser.PixelHeight = ImageHeight; | |
PhotoChooser.ShowCamera = true; | |
PhotoChooser.Completed += new EventHandler<PhotoResult>(PhotoChooser_Completed); | |
} | |
void PhotoChooser_Completed(object sender, PhotoResult e) | |
{ | |
if (e.TaskResult == TaskResult.OK) | |
{ | |
IsolatedStorageFile Store = IsolatedStorageFile.GetUserStoreForApplication(); | |
IsolatedStorageFileStream Stream = new IsolatedStorageFileStream("ph.jpg ", FileMode.Create, FileAccess.Write, Store); | |
WriteableBitmap myImage = new WriteableBitmap(ImageWidth, ImageHeight); | |
myImage.SetSource(e.ChosenPhoto); | |
PageImage.Source = myImage; | |
PageImage.InvalidateArrange(); | |
myImage.SaveJpeg(Stream, ImageWidth, ImageHeight, 0, 100); | |
Stream.Close(); | |
} | |
} | |
protected override void OnNavigatedTo(NavigationEventArgs e) | |
{ | |
base.OnNavigatedTo(e); | |
if (IsolatedStorageFile.GetUserStoreForApplication().FileExists("ph.jpg")) | |
{ | |
IsolatedStorageFile Store = IsolatedStorageFile.GetUserStoreForApplication(); | |
IsolatedStorageFileStream Stream = new IsolatedStorageFileStream("ph.jpg", FileMode.Open, FileAccess.Read, Store); | |
WriteableBitmap myImage = new WriteableBitmap(ImageWidth, ImageHeight); | |
myImage.LoadJpeg(Stream); | |
PageImage.Source = myImage; | |
PageImage.InvalidateArrange(); | |
Stream.Close(); | |
} | |
} | |
private void ToPage2Button_Click(object sender, System.Windows.RoutedEventArgs e) | |
{ | |
NavigationService.Navigate(new Uri("/Page1.xaml", UriKind.Relative)); | |
} | |
private void LoadButton_Click(object sender, System.Windows.RoutedEventArgs e) | |
{ | |
PhotoChooser.Show(); | |
} | |
private void Button_Click(object sender, RoutedEventArgs e) | |
{ | |
} | |
// Sample code for building a localized ApplicationBar | |
//private void BuildLocalizedApplicationBar() | |
//{ | |
// // Set the page's ApplicationBar to a new instance of ApplicationBar. | |
// ApplicationBar = new ApplicationBar(); | |
// // Create a new button and set the text value to the localized string from AppResources. | |
// ApplicationBarIconButton appBarButton = new ApplicationBarIconButton(new Uri("/Assets/AppBar/appbar.add.rest.png", UriKind.Relative)); | |
// appBarButton.Text = AppResources.AppBarButtonText; | |
// ApplicationBar.Buttons.Add(appBarButton); | |
// // Create a new menu item with the localized string from AppResources. | |
// ApplicationBarMenuItem appBarMenuItem = new ApplicationBarMenuItem(AppResources.AppBarMenuItemText); | |
// ApplicationBar.MenuItems.Add(appBarMenuItem); | |
//} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Net; | |
using System.Windows; | |
using System.Windows.Controls; | |
using System.Windows.Navigation; | |
using Microsoft.Phone.Controls; | |
using Microsoft.Phone.Shell; | |
using System.IO.IsolatedStorage; | |
using System.Windows.Media.Imaging; | |
using System.IO; | |
namespace PhotoChoose | |
{ | |
// secondPage is Page1 :D | |
// 1st page Image store into this page | |
// xaml code " <Image x:Name="PageImage" HorizontalAlignment="Left" Height="180" Margin="67,60,0,0" VerticalAlignment="Top" Width="344" Grid.Row="1"/> " | |
// xaml image tag must be take to out of the grid ..... | |
public partial class Page1 : PhoneApplicationPage | |
{ | |
int ImageWidth, ImageHeight; | |
public Page1() | |
{ | |
InitializeComponent(); | |
ImageWidth = (int)PageImage.Width; | |
ImageHeight = (int)PageImage.Height; | |
} | |
private void BackButton_Click(object sender, System.Windows.RoutedEventArgs e) | |
{ | |
NavigationService.GoBack(); | |
} | |
protected override void OnNavigatedTo(NavigationEventArgs e) | |
{ | |
base.OnNavigatedTo(e); | |
if (IsolatedStorageFile.GetUserStoreForApplication().FileExists("ph.jpg")) | |
{ | |
IsolatedStorageFile Store = IsolatedStorageFile.GetUserStoreForApplication(); | |
IsolatedStorageFileStream Stream = new IsolatedStorageFileStream("ph.jpg", FileMode.Open, FileAccess.Read, Store); | |
WriteableBitmap myImage = new WriteableBitmap(ImageWidth, ImageHeight); | |
myImage.LoadJpeg(Stream); | |
PageImage.Source = myImage; | |
PageImage.InvalidateArrange(); | |
Stream.Close(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment