您好我正在創建一個UWP應用程序,並有以下方法來上傳圖片。UWP應用程序添加圖像(路徑)SQLite數據庫
async void imageButton_Click(object sender, RoutedEventArgs e)
{
FileOpenPicker open = new FileOpenPicker();
open.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
open.ViewMode = PickerViewMode.Thumbnail;
// Filter to include a sample subset of file types
open.FileTypeFilter.Clear();
open.FileTypeFilter.Add(".bmp");
open.FileTypeFilter.Add(".png");
open.FileTypeFilter.Add(".jpeg");
open.FileTypeFilter.Add(".jpg");
// Open a stream for the selected file
StorageFile file = await open.PickSingleFileAsync();
// Ensure a file was selected
if (file != null)
{
// Ensure the stream is disposed once the image is loaded
using (IRandomAccessStream fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read))
{
// Set the image source to the selected bitmap
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.DecodePixelHeight = 200;
bitmapImage.DecodePixelWidth = 200;
await bitmapImage.SetSourceAsync(fileStream);
image.Source = bitmapImage;
}
}
}
我SQLite中創建的數據庫,我想將圖像路徑添加到數據庫,但我不知道如何與UWP應用程序實現代碼。謝謝你的幫助。