map improvement

user picture
image crop
This commit is contained in:
2011-03-31 06:24:59 +03:00
parent 833083ca0e
commit c0d31a8652
65 changed files with 3128 additions and 41 deletions
@@ -0,0 +1,58 @@
<phone:PhoneApplicationPage x:Class="MyFriendsAround.WP7.Views.CropPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:binding="clr-namespace:Coding4Fun.Phone.Controls.Binding;assembly=Coding4Fun.Phone.Controls" xmlns:Preview="clr-namespace:Phone7.Fx.Preview;assembly=Phone7.Fx.Preview" xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" xmlns:cmd="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.WP7" FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
DataContext="{Binding Main, Source={StaticResource Locator}}"
mc:Ignorable="d" d:DesignHeight="696" d:DesignWidth="480"
shell:SystemTray.IsVisible="True">
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,12,0,12">
<TextBlock x:Name="ApplicationTitle" Text="{Binding Path=ApplicationTitle}" Style="{StaticResource PhoneTextNormalStyle}"
Foreground="{StaticResource PhoneAccentBrush}" />
<TextBlock x:Name="PageTitle"
Text="{Binding Path=PageNameCropping}" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>
<Grid x:Name="ImageContainer"
Background="Transparent"
Grid.Row="1" HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
>
<Image
HorizontalAlignment="Left"
VerticalAlignment="Top"
Margin="0"
Name="image1"
Stretch="Uniform"
/>
</Grid>
</Grid>
<phone:PhoneApplicationPage.ApplicationBar>
<shell:ApplicationBar IsVisible="True" Opacity="0.8"
IsMenuEnabled="True">
<shell:ApplicationBarIconButton IconUri="/Toolkit.Content/ApplicationBar.Check.png"
Text="Accept"
Click="Accept_Click" />
<shell:ApplicationBarIconButton IconUri="/Toolkit.Content/ApplicationBar.Cancel.png"
Text="Cancel"
Click="Cancel_Click" />
</shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>
</phone:PhoneApplicationPage>
@@ -0,0 +1,179 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Microsoft.Phone;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Tasks;
using MyFriendsAround.WP7.Utils;
using MyFriendsAround.WP7.ViewModel;
using NetworkDetection;
namespace MyFriendsAround.WP7.Views
{
public partial class CropPage : PhoneApplicationPage
{
private int imageSize = 200;
public CropPage()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(CropPage_Loaded);
}
//private BitmapImage imageSrc;
void CropPage_Loaded(object sender, RoutedEventArgs e)
{
if (!NetworkDetector.Instance.GetZuneStatus())
{
PhotoChooserTask task = new PhotoChooserTask();
task.Show();
task.Completed += new EventHandler<PhotoResult>(task_Completed);
//TEST
//imageSrc = new BitmapImage(new Uri("/icons/Penguins.jpg", UriKind.RelativeOrAbsolute));
//image1.Source = imageSrc;
SetPicture();
}
else
{
NavigateBack();
}
}
private void NavigateBack()
{
Container.Instance.Resolve<MainViewModel>("MainViewModel").CropCancel();
}
void task_Completed(object sender, PhotoResult e)
{
if (e.TaskResult == TaskResult.OK)
{
BitmapImage image = new BitmapImage();
image.SetSource(e.ChosenPhoto);
//
image1.Width = this.Width/2;
image1.Height = image1.Width*image.PixelHeight/image.PixelWidth;
image1.Source = image;
SetPicture();
}
else
{
NavigateBack();
}
}
private Rectangle rect;
void SetPicture()
{
rect = new Rectangle();
rect.Opacity = .5;
rect.Fill = new SolidColorBrush(Colors.White);
rect.Height = imageSize;
rect.MaxHeight = imageSize;
rect.MaxWidth = imageSize;
rect.Width = imageSize;
rect.Stroke = new SolidColorBrush(Colors.Red);
rect.StrokeThickness = 2;
rect.Margin = new Thickness(0);
ImageContainer.ManipulationDelta += new EventHandler<ManipulationDeltaEventArgs>(rect_ManipulationDelta);
ImageContainer.Children.Add(rect);
ImageContainer.Height = this.ActualWidth;
ImageContainer.Width = this.ActualWidth;
}
int trX = 0;
int trY = 0;
double scale = 1;
void rect_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
{
if (e.DeltaManipulation.Scale.X > 0 && e.DeltaManipulation.Scale.Y > 0)
{
scale = scale*(e.DeltaManipulation.Scale.X + e.DeltaManipulation.Scale.Y)/2;
}
trX += (int) ((double) e.DeltaManipulation.Translation.X /scale);
trY += (int) ((int) e.DeltaManipulation.Translation.Y /scale);
e.Handled = true;
TransformGroup tg = new TransformGroup();
ScaleTransform st = new ScaleTransform();
st.CenterX = ImageContainer.ActualWidth / 2 - trX;
st.CenterY = ImageContainer.ActualHeight / 2 - trY;
st.ScaleX = scale;
st.ScaleY = scale;
tg.Children.Add(st);
TranslateTransform tr = new TranslateTransform();
tr.X = trX;
tr.Y = trY;
tg.Children.Add(tr);
image1.RenderTransform = tg;
//croppingRectangle
GeneralTransform gt = image1.TransformToVisual(ImageContainer);
Point p = gt.Transform(new Point( 0, 0));
RectangleGeometry geo = new RectangleGeometry();
geo.Rect = new Rect(-p.X / scale, -p.Y / scale, ImageContainer.ActualWidth / scale, ImageContainer.ActualHeight / scale);
image1.Clip = geo;
}
public void Save()
{
WriteBitmap();
}
void WriteBitmap()
{
Rectangle r = (Rectangle)(from c in ImageContainer.Children where c.Opacity == .5 select c).First();
GeneralTransform gt = r.TransformToVisual(image1);
//
WriteableBitmap wbm = new WriteableBitmap(imageSize, imageSize);
wbm.Render(image1, gt.Inverse as Transform);
wbm.Invalidate();
using (MemoryStream stream = new MemoryStream())
{
wbm.SaveJpeg(stream, imageSize, imageSize, 0, 100);
//
stream.Seek(0, SeekOrigin.Begin);
byte[] _imageBytes = new byte[stream.Length];
stream.Read(_imageBytes, 0, _imageBytes.Length);
//save
IsolatedStorageHelper.SaveToLocalStorage("myphoto.jpg", "profiles", _imageBytes);
//
Container.Instance.Resolve<MainViewModel>("MainViewModel").MyPicture = wbm;
}
}
private void Accept_Click(object sender, EventArgs e)
{
Save();
NavigateBack();
}
private void Cancel_Click(object sender, EventArgs e)
{
NavigateBack();
}
}
}
+47 -18
View File
@@ -36,13 +36,38 @@
<Image Source="{Binding PinSource}" />
</Grid>
</ControlTemplate>
<ControlTemplate x:Key="PushpinControlTemplate2"
TargetType="my:Pushpin">
<Grid x:Name="ContentGrid">
<StackPanel Orientation="Vertical">
<Grid Background="{TemplateBinding Background}"
HorizontalAlignment="Left"
MinHeight="10"
MinWidth="29">
<Image x:Name="imgFriend"
Source="{Binding PinImageUrl, Mode=OneWay}"
Margin="2, 2, 2, 24" Width="48" Height="48"
Stretch="Fill">
</Image>
<TextBlock HorizontalAlignment="Left" Text="{Binding PinUserName}" VerticalAlignment="Bottom"
Margin="1" Width="48" Height="24" />
</Grid>
<Polygon Fill="{TemplateBinding Background}"
Points="0,0 29,0 0,29"
Width="29"
Height="29"
HorizontalAlignment="Left" />
</StackPanel>
</Grid>
</ControlTemplate>
</phone:PhoneApplicationPage.Resources>
<!--<i:Interaction.Triggers>
<i:Interaction.Triggers>
<i:EventTrigger EventName="Loaded">
<cmd:EventToCommand Command="{Binding RefreshFriendsCommand}" />
<cmd:EventToCommand Command="{Binding MainLoadCommand}" />
</i:EventTrigger>
</i:Interaction.Triggers>-->
</i:Interaction.Triggers>
<Grid x:Name="LayoutRoot"
Background="Transparent">
@@ -71,28 +96,24 @@
</Button>-->
<my:Map x:Name="map"
HorizontalAlignment="Stretch"
CredentialsProvider="AkCiPfQt9YM0cCkZlltdR3mnFQRkV41l4f-eXFmf3qcBBhBC-EkvD8MuazOkMnE_"
HorizontalAlignment="Stretch" ZoomBarVisibility="Visible"
Margin="6,0,6,0"
VerticalAlignment="Stretch"
Center="{Binding Path=MapCenter, Mode=TwoWay}">
Center="{Binding Path=MapCenter, Mode=TwoWay}"
ZoomLevel="{Binding Path=MapZoom, Mode=TwoWay}"
>
<my:MapItemsControl ItemsSource="{Binding PushPins}">
<my:MapItemsControl.ItemTemplate>
<DataTemplate>
<my:Pushpin Location="{Binding Location}"
Template="{StaticResource PushpinControlTemplate1}">
Background="{StaticResource PhoneAccentBrush}"
Template="{StaticResource PushpinControlTemplate2}">
</my:Pushpin>
</DataTemplate>
</my:MapItemsControl.ItemTemplate>
</my:MapItemsControl>
</my:Map>
<toolkit:PerformanceProgressBar HorizontalAlignment="Left"
Margin="0,-151,0,0"
Name="performanceProgressBar1"
VerticalAlignment="Top"
Height="18"
Width="480"
ActualIsIndeterminate="{Binding Path=IsBusy}"
IsIndeterminate="{Binding Path=IsBusy}" />
</Grid>
@@ -107,7 +128,7 @@
<TextBlock x:Name="ApplicationTitle"
Margin="12, 12, 0, 0"
Text="{Binding ApplicationTitle}"
Foreground="#00fffc"
Foreground="{StaticResource PhoneAccentBrush}"
Style="{StaticResource PhoneTextNormalStyle}" />
<Grid Margin="0,6,6,6"
Height="80">
@@ -118,9 +139,9 @@
Opacity="1"
>
<Image x:Name="imgMine"
Source="{Binding MyPicture}">
Source="{Binding MyPicture, Mode=OneWay}" Margin="0" Stretch="Fill" >
</Image>
<Border Background="#00fffc"
<Border Background="{StaticResource PhoneAccentBrush}"
Width="80"
Height="25"
HorizontalAlignment="Stretch"
@@ -133,10 +154,18 @@
HorizontalAlignment="Left"
VerticalAlignment="Center"
Margin="2"
Text="{Binding MyName}" />
Text="{Binding MyName, Mode=OneWay}" />
</Border>
</Grid>
<toolkit:PerformanceProgressBar HorizontalAlignment="Left"
Margin="0,0,0,0"
Name="performanceProgressBar1"
VerticalAlignment="Top"
Height="18"
Width="480"
ActualIsIndeterminate="{Binding Path=IsBusy}"
IsIndeterminate="{Binding Path=IsBusy}" />
</Grid>
</Grid>
@@ -13,6 +13,12 @@
mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480"
shell:SystemTray.IsVisible="True">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Loaded">
<cmd:EventToCommand Command="{Binding MainLoadCommand}" />
</i:EventTrigger>
</i:Interaction.Triggers>
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
@@ -21,8 +27,9 @@
</Grid.RowDefinitions>
<!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock x:Name="ApplicationTitle" Text="{Binding Path=ApplicationTitle}" Style="{StaticResource PhoneTextNormalStyle}"/>
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,12,0,12">
<TextBlock x:Name="ApplicationTitle" Text="{Binding Path=ApplicationTitle}" Style="{StaticResource PhoneTextNormalStyle}"
Foreground="{StaticResource PhoneAccentBrush}" />
<TextBlock x:Name="PageTitle"
Text="{Binding Path=PageNameSettings}" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>
@@ -35,7 +42,8 @@
Margin="6,0,0,6"
>
<TextBlock Text="My Name"
Style="{StaticResource PhoneTextTitle3Style}" />
Style="{StaticResource PhoneTextTitle3Style}"
/>
<TextBox Height="67"
HorizontalAlignment="Stretch"
Name="txtMyName"
@@ -48,14 +56,15 @@
Margin="0, 24, 0, 24"
Width="200"
Height="200"
Background="#00fffc"
Background="{StaticResource PhoneAccentBrush}"
BorderThickness="0"
Padding="0"
>
<Image x:Name="myPicture"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Margin="3"
Stretch="Uniform"
Margin="1"
Source="{Binding MyPicture}"></Image>
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">