当前位置:编程学习 > wap >>

Windows Phone在隔离存储里存取图片文件

 

作为Windows Phone的初学者,第一个练手小应用是一个类似备忘录的软件,功能不是太多,涉及到即时任务,灵感,图文的一些记录。对于即时拍照然后附上相应描述再保存在独立存储里面,刚开始不太懂,搞了好几天(毕竟是新手),总算是搞定了,在此奉上关于照片存取的小小收获,给予像我一样的新手一点小小的帮助吧,也许对有些人有用而对有些人不值一提吧。

一共两个页面,第一个为MainPage.xaml,代码如下:

 1  <!--ContentPanel - place additional content here-->

 2         <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">

 3             <Image Name="PhotoImage" Height="342" HorizontalAlignment="Left" Margin="9,6,0,0"  Stretch="Fill" VerticalAlignment="Top" Width="441"/>

 4             <Button Name="SaveButton" Click="SaveButton_Click" Content="保存" Height="72" HorizontalAlignment="Left" Margin="7,482,0,0"  VerticalAlignment="Top" Width="441">

 5                 <Button.Background>

 6                     <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">

 7                         <GradientStop Color="Black" Offset="0"/>

 8                         <GradientStop Color="#FFEB1818" Offset="1"/>

 9                     </LinearGradientBrush>

10                 </Button.Background>

11             </Button>

12             <TextBlock Height="30" HorizontalAlignment="Left" Margin="27,442,0,0" Name="textBlock1" Text="输入照片名:" FontSize="25" VerticalAlignment="Top"/>

13             <TextBox Name="PhotoName" Height="72" HorizontalAlignment="Left" Margin="165,424,0,0"  Text="" VerticalAlignment="Top" Width="284">

14                 <TextBox.Background>

15                     <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">

16                         <GradientStop Color="Black" Offset="0"/>

17                         <GradientStop Color="#FFD01818" Offset="1"/>

18                     </LinearGradientBrush>

19                 </TextBox.Background>

20             </TextBox>

21             <Button Name="TakePhotoButton" Click="TakePhotoButton_Click" Content="拍照" Height="72" Margin="9,366,8,0" VerticalAlignment="Top">

22                 <Button.Background>

23                     <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">

24                         <GradientStop Color="Black" Offset="0"/>

25                         <GradientStop Color="#FFD61212" Offset="1"/>

26                     </LinearGradientBrush>

27                 </Button.Background>

28             </Button>

29         </Grid>

30     </Grid>

31 

32     <!--Sample code showing usage of ApplicationBar-->

33     <phone:PhoneApplicationPage.ApplicationBar>

34         <shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">

35             <shell:ApplicationBarIconButton IconUri="/Images/appbar.feature.search.rest.png" Text="查看" Click="ApplicationBarIconButton_Click"/>

36         </shell:ApplicationBar>

37     </phone:PhoneApplicationPage.ApplicationBar>

后台代码如下:

  MainPage.xaml.cs

 1 using System;

 2 using System.Collections.Generic;

 3 using System.Linq;

 4 using System.Net;

 5 using System.Windows;

 6 using System.Windows.Controls;

 7 using System.Windows.Documents;

 8 using System.Windows.Input;

 9 using System.Windows.Media;

10 using System.Windows.Media.Animation;

11 using System.Windows.Shapes;

12 using Microsoft.Phone.Controls;

13 using Microsoft.Phone.Tasks;

14 using Microsoft.Phone;

15 using System.IO;

16 using System.IO.IsolatedStorage;

17

18 namespace 在隔离存储中存取照片

19 {

20     public partial class MainPage : PhoneApplicationPage

21     {

22         // Constructor

23         string filename;

24         byte[] _imageAsByte;

25         public MainPage()

26         {

补充:移动开发 , Windows Phone ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,