0
我爲uwp編寫應用程序imageControl.Source(C#UWP)
我有PCL,其中是打開相機,拍照並保存它的方法。
這是PCL中的方法代碼。
public async void PhotoTake()
{
CameraCaptureUI captureUI = new CameraCaptureUI();
captureUI.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg;
captureUI.PhotoSettings.CroppedSizeInPixels = new Size(200, 200);
StorageFile photo = await captureUI.CaptureFileAsync(CameraCaptureUIMode.Photo);
if (photo == null)
{
return;
}
StorageFolder destinationFolder =
await ApplicationData.Current.LocalFolder.CreateFolderAsync("ProfilePhotoFolder", CreationCollisionOption.OpenIfExists);
await photo.CopyAsync(destinationFolder, "ProfilePhoto.jpg", NameCollisionOption.ReplaceExisting);
await photo.DeleteAsync();
IRandomAccessStream stream = await photo.OpenAsync(FileAccessMode.Read);
BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream);
SoftwareBitmap softwareBitmap = await decoder.GetSoftwareBitmapAsync();
SoftwareBitmap softwareBitmapBGR8 = SoftwareBitmap.Convert(softwareBitmap,
BitmapPixelFormat.Bgra8,
BitmapAlphaMode.Premultiplied);
SoftwareBitmapSource bitmapSource = new SoftwareBitmapSource();
await bitmapSource.SetBitmapAsync(softwareBitmapBGR8);
}
在xaml中我有圖像。我需要在此圖像中顯示照片。
當我明白我需要寫水木清華這樣imageControl.Source = bitmapSource;
但我的,當我寫我有 Error CS0103 The name 'bitmapSource' does not exist in the current context
這裏是我的xaml.cs文件
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
CameraOpening cam = new CameraOpening();
cam.PhotoTake();
imageControl.Source = bitmapSource;
}
}
我怎麼hadle這個錯誤?
感謝的
人,你有沒有試着挖成C#第一? –