Windows Phone在隔离存储里存取图片文件
2011-11-04 23:13
351 查看
作为Windows Phone的初学者,第一个练手小应用是一个类似备忘录的软件,功能不是太多,涉及到即时任务,灵感,图文的一些记录。对于即时拍照然后附上相应描述再保存在独立存储里面,刚开始不太懂,搞了好几天(毕竟是新手),总算是搞定了,在此奉上关于照片存取的小小收获,给予像我一样的新手一点小小的帮助吧,也许对有些人有用而对有些人不值一提吧。
一共两个页面,第一个为MainPage.xaml,代码如下:
后台代码如下:
Page1.xaml.cs
运行效果如下:
希望对大家有所帮助,嘻嘻。祝大家WP开发更上一城楼,大家以后都去赚美刀!!!
一共两个页面,第一个为MainPage.xaml,代码如下:
<!--ContentPanel - place additional content here--> <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"> <Image Name="PhotoImage" Height="342" HorizontalAlignment="Left" Margin="9,6,0,0" Stretch="Fill" VerticalAlignment="Top" Width="441"/> <Button Name="SaveButton" Click="SaveButton_Click" Content="保存" Height="72" HorizontalAlignment="Left" Margin="7,482,0,0" VerticalAlignment="Top" Width="441"> <Button.Background> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="Black" Offset="0"/> <GradientStop Color="#FFEB1818" Offset="1"/> </LinearGradientBrush> </Button.Background> </Button> <TextBlock Height="30" HorizontalAlignment="Left" Margin="27,442,0,0" Name="textBlock1" Text="输入照片名:" FontSize="25" VerticalAlignment="Top"/> <TextBox Name="PhotoName" Height="72" HorizontalAlignment="Left" Margin="165,424,0,0" Text="" VerticalAlignment="Top" Width="284"> <TextBox.Background> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="Black" Offset="0"/> <GradientStop Color="#FFD01818" Offset="1"/> </LinearGradientBrush> </TextBox.Background> </TextBox> <Button Name="TakePhotoButton" Click="TakePhotoButton_Click" Content="拍照" Height="72" Margin="9,366,8,0" VerticalAlignment="Top"> <Button.Background> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="Black" Offset="0"/> <GradientStop Color="#FFD61212" Offset="1"/> </LinearGradientBrush> </Button.Background> </Button> </Grid> </Grid> <!--Sample code showing usage of ApplicationBar--> <phone:PhoneApplicationPage.ApplicationBar> <shell:ApplicationBar IsVisible="True" IsMenuEnabled="True"> <shell:ApplicationBarIconButton IconUri="/Images/appbar.feature.search.rest.png" Text="查看" Click="ApplicationBarIconButton_Click"/> </shell:ApplicationBar> </phone:PhoneApplicationPage.ApplicationBar>
后台代码如下:
Page1.xaml.cs
using System; using System.Collections.Generic; 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.Shapes; using Microsoft.Phone.Controls; using System.IO; using System.IO.IsolatedStorage; using System.Windows.Media.Imaging; namespace 在隔离存储中存取照片 { public partial class Page1 : PhoneApplicationPage { IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication(); public Page1() { InitializeComponent(); } private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e) { List<PhotoFile> filelist = new List<PhotoFile>(); if (file.GetFileNames() != null) { foreach (string filename in file.GetFileNames()) { PhotoFile photo = new PhotoFile(); BitmapImage bmp = new BitmapImage(); using (IsolatedStorageFileStream filestream = file.OpenFile(filename, FileMode.Open, FileAccess.ReadWrite)) { bmp.SetSource(filestream); filestream.Flush(); filestream.Close(); photo.Image = bmp; photo.ImageName = " 照片名:"+filename; } filelist.Add(photo); } listBox1.ItemsSource = filelist; } } private void ApplicationBarIconButton_Click(object sender, EventArgs e) { NavigationService.Navigate(new Uri("/MainPage.xaml",UriKind.Relative)); } } }
运行效果如下:
希望对大家有所帮助,嘻嘻。祝大家WP开发更上一城楼,大家以后都去赚美刀!!!
相关文章推荐
- 【转】Windows Phone在隔离存储里存取图片文件
- 【转】Windows Phone在隔离存储里存取图片文件
- 【转】Windows Phone在隔离存储里存取图片文件
- 【转】Windows Phone在隔离存储里存取图片文件
- 【转】Windows Phone在隔离存储里存取图片文件
- 【转】Windows Phone在隔离存储里存取图片文件
- Windows Phone 7 隔离存储空间及文件操作
- MySQL如何存储图片?---一个向数据库存取image文件的jsp程序
- Windows Phone 隔离存储空间及文件操作
- MySQL如何存储图片?---一个向数据库存取image文件的jsp程序
- Utils 图片通过Url获取流用Sftp向文件服务器存储
- 将上传图片文件转成二进制流再存储
- Windows Phone开发(28):隔离存储B 转:http://blog.csdn.net/tcjiaan/article/details/7436959
- Windows Phone 8的独立存储文件系统
- 20.获取网络图片,将图片存储在文件,缓存中,然后先从缓存中读取,没有再从文件中读取
- image文件图片显示,存储,读取问题
- LINUX目录和文件各自的权限说明,以及目录和文件权限之间的关系(应用:配置linux下上传图片的存储目录)
- 将图片文件分解,再利用管道流合成 存储对象
- 生成黑白画笔,android使用系统浏览器打开网页,将Bitmap图片存储在本地JPG文件的方法
- SQL Server 中图片和文件的存取