2016-08-24 2 views
0

캡처 용으로 MediaCapture API를 사용하고 있습니다. 하지만 사진을 앱의 캐시에 저장하는 방법은 모르지만 기기의 폴더에 저장하는 것은 아닙니다.사진을 앱의 캐시에 저장 UWP C#

private async void btnPhoto_Click(object sender, RoutedEventArgs e) 
{ 
    // This is where we want to save to. 
    var storageFolder = KnownFolders.SavedPictures; 

    // Create the file that we're going to save the photo to. 
    var file = await storageFolder.CreateFileAsync("sample.jpg", CreationCollisionOption.GenerateUniqueName); 

    // Update the file with the contents of the photograph.   
    await _mediaCapture.CapturePhotoToStorageFileAsync(ImageEncodingProperties.CreateJpeg(), file); 
} 

사용자는 다섯 장의 사진을 캡처하고 서버에 전송하고이 장치에 사진을 저장하지 마십시오 필요가 있습니다. 어떻게 구현할 수 있습니까?

답변

0

그러나 사진을 장치의 폴더가 아니라 폴더에 저장하는 방법을 모르겠습니다.

나는 임시 StorageFile을 만들 ApplicationData.TemporaryFolder을 사용하는 것이 좋습니다 :

var file=await ApplicationData.Current.TemporaryFolder.CreateFileAsync("sample.jpg", CreationCollisionOption.GenerateUniqueName); 

그것은 디스크 캐시 임시 파일을 생성합니다. 시스템 유지 관리 작업은 언제든지이 파일을 자동으로 삭제합니다. 사용자는 디스크 정리를 사용하여 이러한 파일을 삭제할 수도 있습니다.

정말로 디스크에 파일을 만들고 싶지 않은 경우.

var stream = new InMemoryRandomAccessStream(); 
await _mediaCapture.CapturePhotoToStreamAsync(ImageEncodingProperties.CreateJpeg(), stream); 

또는 앱에이를 표시 할 경우 SoftwareBitmap에 사진을 저장합니다 : 당신은 InMemoryRandomAccessStream를 사용하여 사진을 캐시 할 수

//save the photo to softwareBitmap: 
var lowLagCapture = await _mediaCapture.PrepareLowLagPhotoCaptureAsync(ImageEncodingProperties.CreateUncompressed(MediaPixelFormat.Bgra8)); 
var capturePhoto = await lowLagCapture.CaptureAsync(); 
SoftwareBitmap softwareBitmap = capturePhoto.Frame.SoftwareBitmap; 
await lowLagCapture.FinishAsync(); 

//load the image in image tag: 
if (softwareBitmap.BitmapPixelFormat != BitmapPixelFormat.Bgra8 || 
softwareBitmap.BitmapAlphaMode == BitmapAlphaMode.Straight) 
{ 
    softwareBitmap = SoftwareBitmap.Convert(softwareBitmap, BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied); 
} 
var source = new SoftwareBitmapSource(); 
await source.SetBitmapAsync(softwareBitmap); 
mainPageImage.Source = source;//mainPageImage is the image tag name