private async void GetFile()
{
Uri source = new Uri(imgUrl);
StorageFile destinationFile;
try
{
destinationFile = await ApplicationData.Current.LocalFolder.CreateFileAsync(
"downloadimage.jpg", CreationCollisionOption.GenerateUniqueName);
}
catch (FileNotFoundException ex)
{
return;
}
BackgroundDownloader downloader = new BackgroundDownloader();
DownloadOperation download = downloader.CreateDownload(source, destinationFile);
await download.StartAsync();
//ResponseInformation response = download.GetResponseInformation();
var stream = await download.ResultFile.OpenReadAsync();
BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream);
InMemoryRandomAccessStream ras = new InMemoryRandomAccessStream();
BitmapEncoder enc = await BitmapEncoder.CreateForTranscodingAsync(ras, decoder);
BitmapBounds bounds = new BitmapBounds();
bounds.Height = 274;
bounds.Width = 382;
bounds.Y = 0;
bounds.X = 0;
enc.BitmapTransform.Bounds = bounds;
await enc.FlushAsync();
BitmapImage bImg = new BitmapImage();
bImg.SetSource(ras);
xImage.Source = bImg;
//2
InMemoryRandomAccessStream ras2 = new InMemoryRandomAccessStream();
BitmapEncoder enc2 = await BitmapEncoder.CreateForTranscodingAsync(ras2, decoder);
BitmapBounds bounds2 = new BitmapBounds();
bounds2.Height = 274;
bounds2.Width = 382;
bounds2.Y = 274;
bounds2.X = 0;
enc2.BitmapTransform.Bounds = bounds2;
await enc2.FlushAsync();
BitmapImage bImg2 = new BitmapImage();
bImg2.SetSource(ras2);
xImage2.Source = bImg2;
var filed = await ApplicationData.Current.LocalFolder.GetFilesAsync();
foreach (var item in filed)
{
//그냥 모두 삭제 삭제 안된 파일이 있을경우 파일이 커지는경우를 방지
await item.DeleteAsync();
}
}
참고
다운로드
crop
http://stackoverflow.com/questions/12349611/how-to-resize-image-in-c-sharp-winrt-winmd
삭제:
http://stackoverflow.com/questions/14978526/how-delete-file-in-localstorage-on-winrt
'Windows8 App' 카테고리의 다른 글
TextBlock에서 라인 띄우는 법 (0) | 2013.11.22 |
---|---|
T Generic 리턴하기 (0) | 2013.10.15 |
[winrt] dispatcher의 활용 (0) | 2013.07.23 |
[windows8] 셋팅 페이지 보이게 하기 (0) | 2013.07.11 |
[Window 8] 기기 해상도와 DPI 값 얻어오기 (0) | 2013.07.05 |