[英]how to get latest captured image in universal windows application using c#
i am developing a solution where i have to capture image from my windows phone mobile application using CaptureElement after capturing image i should preview the image to the user after that if user click on Upload button then save this image name and path to the database. 我正在开发一个解决方案,我必须在捕获图像后使用CaptureElement从我的Windows手机移动应用程序捕获图像我应该在用户点击上传按钮后将图像预览到用户,然后将此图像名称和路径保存到数据库。
I use this source code to capture and preview but it is showing me all the images. 我使用此源代码捕获和预览,但它向我显示所有图像。
string fileName = "Image.jpg";// TextBox
fileName = Path.GetFileName(fileName);
Windows.Storage.IStorageFile photo =
await Windows.Storage.KnownFolders.PicturesLibrary.CreateFileAsync
(fileName, Windows.Storage.CreationCollisionOption.GenerateUniqueName);
await mediaCapture.CapturePhotoToStorageFileAsync
(Windows.Media.MediaProperties.ImageEncodingProperties.CreateJpeg(), photo);
CaptureBtn.Visibility = Visibility.Collapsed;
ImageView.Visibility = Visibility.Visible;
previewElement.Visibility = Visibility.Collapsed;
UploadBtn.Visibility = Visibility.Visible;
CancelBtn.Visibility = Visibility.Visible;
//Here i am htrying to access file from SD card
// Get the Pictures library
Windows.Storage.StorageFolder picturesFolder =
Windows.Storage.KnownFolders.PicturesLibrary;
IReadOnlyList<StorageFolder> folders =
await picturesFolder.GetFoldersAsync();
foreach (StorageFolder folder in folders)
{
// Get and process files in folder
IReadOnlyList<StorageFile> fileList = await folder.GetFilesAsync();
foreach (StorageFile file in fileList)
{
Windows.UI.Xaml.Media.Imaging.BitmapImage bitmapImage =
new Windows.UI.Xaml.Media.Imaging.BitmapImage();
// Open a stream for the selected file.
// The 'using' block ensures the stream is disposed
// after the image is loaded.
using (Windows.Storage.Streams.IRandomAccessStream fileStream =
await file.OpenAsync(Windows.Storage.FileAccessMode.Read))
{
if (file.DisplayName == fileName)
{
// Set the image source to the selected bitmap.
Windows.UI.Xaml.Media.Imaging.BitmapImage bitmapImages =
new Windows.UI.Xaml.Media.Imaging.BitmapImage();
bitmapImages.SetSource(fileStream);
ImageView.Source = bitmapImages;
}
}
}
}
How can i do this? 我怎样才能做到这一点? Thank you in advance.
先感谢您。
If I have understand you right solution is simple: 如果我理解你正确的解决方案很简单:
string fileName = "Image.jpg";// TextBox
fileName = Path.GetFileName(fileName);
Windows.Storage.IStorageFile photo =
await Windows.Storage.KnownFolders.PicturesLibrary.CreateFileAsync
(fileName, Windows.Storage.CreationCollisionOption.GenerateUniqueName);
await mediaCapture.CapturePhotoToStorageFileAsync
(Windows.Media.MediaProperties.ImageEncodingProperties.CreateJpeg(), photo);
CaptureBtn.Visibility = Visibility.Collapsed;
ImageView.Visibility = Visibility.Visible;
previewElement.Visibility = Visibility.Collapsed;
UploadBtn.Visibility = Visibility.Visible;
CancelBtn.Visibility = Visibility.Visible;
using (Windows.Storage.Streams.IRandomAccessStream fileStream =
await photo.OpenAsync(Windows.Storage.FileAccessMode.Read))
{
// Set the image source to the selected bitmap.
Windows.UI.Xaml.Media.Imaging.BitmapImage bitmapImages =
new Windows.UI.Xaml.Media.Imaging.BitmapImage();
bitmapImages.SetSource(fileStream);
ImageView.Source = bitmapImages;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.