资料
http://msdn.microsoft.com/zh-cn/library/windows/apps/jj710186.aspx
NG4HW-VH26C-733KW-K6F98-J8CK4
vs YKCW6-BPFPF-BT8C9-7DCTH-QXGWC
用到快捷浏览图片,需要用到网络请求并显示实时显示网络请求的进度,采用了BitmapImage:
如下:
http://xamlspy.com/
var bitmapImage = new BitmapImage(new Uri(this.URL, UriKind.Absolute));
bitmapImage.DownloadProgress += bitmapImage_DownloadProgress;
void bitmapImage_DownloadProgress(object sender, DownloadProgressEventArgs e)
{
progressBar.Value = e.Progress;
}
e.Progress就是网络请求图片的进度值。
如下:
http://xamlspy.com/
var bitmapImage = new BitmapImage(new Uri(this.URL, UriKind.Absolute));
bitmapImage.DownloadProgress += bitmapImage_DownloadProgress;
void bitmapImage_DownloadProgress(object sender, DownloadProgressEventArgs e)
{
progressBar.Value = e.Progress;
}
e.Progress就是网络请求图片的进度值。
Show.XAML
<Viewbox x:Name="viewBox" HorizontalAlignment="Left" Width="1366" Margin="0,0,0,-52" Grid.RowSpan="2" SizeChanged="viewBox_SizeChanged">
<GridView x:Name="gvShow" BorderThickness="10" BorderBrush="Black" HorizontalAlignment="Left" Grid.Row="1" Width="1366" Margin="0,5,0,0" Height="708" SelectionMode="None">
<GridView.ItemTemplate>
<DataTemplate>
<Grid Tapped="Grid_Tapped_1" >
<StackPanel>
<Image x:Name="imgSmall" Width="400" HorizontalAlignment="Left" Grid.Row="1" Source="{Binding ImageSmall}" Stretch="UniformToFill"/>
</StackPanel>
<ScrollViewer x:Name="scrollViewer" BorderThickness="0" HorizontalAlignment="Center" ZoomMode="Enabled" MaxZoomFactor="20" HorizontalScrollMode="Enabled" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden">
<StackPanel>
<Image x:Name="imgBig" Visibility="Collapsed" HorizontalAlignment="Left" Grid.Row="1" Source="{Binding ImageBig}" Stretch="UniformToFill"/>
</StackPanel>
</ScrollViewer>
</Grid>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
</Viewbox>
<GridView x:Name="gvShow" BorderThickness="10" BorderBrush="Black" HorizontalAlignment="Left" Grid.Row="1" Width="1366" Margin="0,5,0,0" Height="708" SelectionMode="None">
<GridView.ItemTemplate>
<DataTemplate>
<Grid Tapped="Grid_Tapped_1" >
<StackPanel>
<Image x:Name="imgSmall" Width="400" HorizontalAlignment="Left" Grid.Row="1" Source="{Binding ImageSmall}" Stretch="UniformToFill"/>
</StackPanel>
<ScrollViewer x:Name="scrollViewer" BorderThickness="0" HorizontalAlignment="Center" ZoomMode="Enabled" MaxZoomFactor="20" HorizontalScrollMode="Enabled" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden">
<StackPanel>
<Image x:Name="imgBig" Visibility="Collapsed" HorizontalAlignment="Left" Grid.Row="1" Source="{Binding ImageBig}" Stretch="UniformToFill"/>
</StackPanel>
</ScrollViewer>
</Grid>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
</Viewbox>
Show.XAML.CS
async private void Open()
{
ObservableCollection<ImageItem> imageItemListBig = new ObservableCollection<ImageItem>();
ObservableCollection<ImageItem> imageItemListSmall = new ObservableCollection<ImageItem>();
FileOpenPicker openPicker = new FileOpenPicker();
openPicker.ViewMode = PickerViewMode.Thumbnail;
openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
openPicker.FileTypeFilter.Add(".jpg");
openPicker.FileTypeFilter.Add(".gif");
openPicker.FileTypeFilter.Add(".png");
openPicker.FileTypeFilter.Add(".bmp");
var fileList = await openPicker.PickMultipleFilesAsync();
if (fileList.Count > 0)
{
foreach (var item in fileList)
{
//缩略图
using (StorageItemThumbnail thumbnail = await item.GetThumbnailAsync(ThumbnailMode.PicturesView, IMAGESIZE, ThumbnailOptions.ResizeThumbnail))
{
if (null != thumbnail)
{
ImageItem imageItemSmall = new ImageItem();
imageItemSmall.ImageSmall.SetSource(thumbnail);
imageItemListSmall.Add(imageItemSmall);
}
}
}
}
gvShow.ItemsSource = imageItemListSmall;
}
{
ObservableCollection<ImageItem> imageItemListBig = new ObservableCollection<ImageItem>();
ObservableCollection<ImageItem> imageItemListSmall = new ObservableCollection<ImageItem>();
FileOpenPicker openPicker = new FileOpenPicker();
openPicker.ViewMode = PickerViewMode.Thumbnail;
openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
openPicker.FileTypeFilter.Add(".jpg");
openPicker.FileTypeFilter.Add(".gif");
openPicker.FileTypeFilter.Add(".png");
openPicker.FileTypeFilter.Add(".bmp");
var fileList = await openPicker.PickMultipleFilesAsync();
if (fileList.Count > 0)
{
foreach (var item in fileList)
{
//缩略图
using (StorageItemThumbnail thumbnail = await item.GetThumbnailAsync(ThumbnailMode.PicturesView, IMAGESIZE, ThumbnailOptions.ResizeThumbnail))
{
if (null != thumbnail)
{
ImageItem imageItemSmall = new ImageItem();
imageItemSmall.ImageSmall.SetSource(thumbnail);
imageItemListSmall.Add(imageItemSmall);
}
}
}
}
gvShow.ItemsSource = imageItemListSmall;
}
ImageIteam.cs
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
if (this.PropertyChanged != null)
{
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
//缩略图
private BitmapImage _ImageSmall = new BitmapImage();
public BitmapImage ImageSmall
{
get
{
return _ImageSmall;
}
set
{
if (_ImageSmall != value)
{
_ImageSmall = value; this.OnPropertyChanged("ImageSmall");
}
}
}
//缩略图
public void SetImageSmall(String path)
{
ImageSmall = new BitmapImage(new Uri(path));
}
protected virtual void OnPropertyChanged(string propertyName)
{
if (this.PropertyChanged != null)
{
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
//缩略图
private BitmapImage _ImageSmall = new BitmapImage();
public BitmapImage ImageSmall
{
get
{
return _ImageSmall;
}
set
{
if (_ImageSmall != value)
{
_ImageSmall = value; this.OnPropertyChanged("ImageSmall");
}
}
}
//缩略图
public void SetImageSmall(String path)
{
ImageSmall = new BitmapImage(new Uri(path));
}
基于tim heuer最新提供的方法
他相关post的地址:
http://timheuer.com/blog/archive/2012/08/07/updated-how-to-using-sqlite-from-windows-store-apps.aspx
以下是实践过程:
step 1:创建一个metro工程
step 2:在工具,选择扩展与更新中,选择联机(online),在搜索框内输入sqlite
将会发现一个叫做sqlite for window runtime的玩意儿,点击安装
step 3:在引用中,选择windows,扩展,把Mircosoft visual c++ runtime package以及sqlite for windows runtime二者勾选上
勾选Mircosoft visual c++ runtime package是作者推荐,据说这样子才不会出问题。有兴趣的可以深究下原因。
step 4:
点选解决方案,选择属性,配置属性,将平台选择为对应的平台,暂时不支持any cpu
step 5:
点击工程,选择管理nuget包,在联机中搜索sqlite-net,点击安装
安装成功后会生成两个文件:SQLite.cs与SQLiteAsync
至此,就完成了sqlite的安装,下面提供一段简陋的测试代码:
using SQLite; |
02 |
|
03 |
public MainPage() |
04 |
{ |
05 |
this .InitializeComponent(); |
06 |
test(); |
07 |
} |
08 |
|
09 |
private async void test() |
10 |
{ |
11 |
SQLiteAsyncConnection conn = new SQLiteAsyncConnection( "people" ); |
12 |
await conn.CreateTableAsync<Person>(); |
13 |
|
14 |
} |
15 |
|
16 |
Person.cs: |
17 |
|
18 |
public class Person |
19 |
{ |
20 |
[PrimaryKey, AutoIncrement] |
21 |
public int Id { get ; set ; } |
22 |
|
23 |
[MaxLength(30)] |
24 |
public string Name { get ; set ; } |
25 |
|
26 |
[MaxLength(30)] |
27 |
public string Surname { get ; set ; } |
28 |
|
29 |
|
如题, 在Win8种,想生成图片的缩略图,有什么方法呢。最好生成的是byte[],谢谢
StorageFile.GetThumbnailAsync
http://msdn.microsoft.com/zh-CN/ ... /apps/br227212.aspx
http://msdn.microsoft.com/en-us/ ... .thumbnailmode.aspx
http://msdn.microsoft.com/zh-CN/ ... /apps/br227212.aspx
http://msdn.microsoft.com/en-us/ ... .thumbnailmode.aspx
网上找到的代码
BitmapImage bitmap = new BitmapImage();
private async void Button_Click_1(object sender, RoutedEventArgs e)
{
bitmap.SetSource(await GetResourceThumbnail("test.png", 190));
img.Source = bitmap;
}
public async Task<IRandomAccessStream> GetResourceThumbnail(string path, uint size)
{
var file = await KnownFolders.PicturesLibrary.GetFileAsync(path).AsTask().ConfigureAwait(false);
return await file.GetThumbnailAsync(ThumbnailMode.PicturesView, size, ThumbnailOptions.UseCurrentScale).AsTask().ConfigureAwait(false);
}
BitmapImage bitmap = new BitmapImage();
private async void Button_Click_1(object sender, RoutedEventArgs e)
{
bitmap.SetSource(await GetResourceThumbnail("test.png", 190));
img.Source = bitmap;
}
public async Task<IRandomAccessStream> GetResourceThumbnail(string path, uint size)
{
var file = await KnownFolders.PicturesLibrary.GetFileAsync(path).AsTask().ConfigureAwait(false);
return await file.GetThumbnailAsync(ThumbnailMode.PicturesView, size, ThumbnailOptions.UseCurrentScale).AsTask().ConfigureAwait(false);
}