简体   繁体   English

如何使用c#在通用Windows应用程序中获取最新捕获的图像

[英]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.

相关问题 C#通用Windows应用程序如何从互联网获取时间 - C# Universal Windows Application How to get time from internet 如何打开本机应用程序以捕获视频,然后使用C#在Windows Phone 8中捕获后返回我的应用程序? - How to open the native application to capture a video then return to my app once captured in Windows Phone 8 using C#? 使用C#将颜色合并到位图中(通用Windows应用程序) - Merging a color into a bitmap using c# (universal windows application) 我可以使用DirectX和C#开发Windows通用应用程序吗 - Can I develop a Windows Universal Application using DirectX and C# 在通用Windows应用程序(c#)中复制对象 - Copy an object in universal Windows Application (c#) 使用C#中的通用Windows应用程序进行图像编辑 - Image editing with universal windows app in C# 在C#中使用BitBlt捕获的屏幕截图在Windows 10上显示黑色图像 - Screenshot captured using BitBlt in C# results a black image on Windows 10 如何在Windows 7中使用C#获取防病毒客户端的最新补丁更新 - How to get the latest patch updates of antivirus client in Windows 7 in C# 如何使用C#应用程序获取图像标签 - How to get Image tag using C# application 在Windows Universal App中使用C#获取设备信息(Windows 10) - Get Device Info using C# in Windows Universal App (Windows 10)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM