Windows Phone C#位图图像调用 [英] Windows Phone C# Bitmap Image Call

查看:71
本文介绍了Windows Phone C#位图图像调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


你好我想问我怎么能让我有拍照的代码并将它们保存到手机存储但是我想知道如何改变代码来拍照并将这张照片保存到变量例如这个并在任何地方调用这张照片我想要

Hello I want to ask how I can make that i have code for taking pictures and save them to phone storage but i want to know how to change code to take picture and save this picture to variable for example to this and call this picture wherever i want

private static String images { get; set; }

public String getImages()
        {
            return images;
        }



拍照代码:

Taking photo code:

 /// captures and saves the 15:9 image with rotation and cropping applied
    private async void CaptureFifteenByNineImage()
    {
        //declare string for filename
        string captureFileName = string.Empty;
        //declare image format
        ImageEncodingProperties format = ImageEncodingProperties.CreateJpeg();

        using (var imageStream = new InMemoryRandomAccessStream())
        {
            //generate stream from MediaCapture
            await captureManager.CapturePhotoToStreamAsync(format, imageStream);

            //create decoder and transform
            BitmapDecoder dec = await BitmapDecoder.CreateAsync(imageStream);
            BitmapTransform transform = new BitmapTransform();

            //rotate the image
            transform.Rotation = BitmapRotation.Clockwise90Degrees;
            transform.Bounds = GetFifteenByNineBounds();

            //get the conversion data that we need to save the cropped and rotated image
            BitmapPixelFormat pixelFormat = dec.BitmapPixelFormat;
            BitmapAlphaMode alpha = dec.BitmapAlphaMode;

            //read the PixelData
            PixelDataProvider pixelProvider = await dec.GetPixelDataAsync(
                pixelFormat,
                alpha,
                transform,
                ExifOrientationMode.RespectExifOrientation,
                ColorManagementMode.ColorManageToSRgb
                );
            byte[] pixels = pixelProvider.DetachPixelData();

            //generate the file
            StorageFolder folder = KnownFolders.SavedPictures;
            StorageFile capturefile = await folder.CreateFileAsync("photo_" + DateTime.Now.Ticks.ToString() + ".jpg", CreationCollisionOption.ReplaceExisting);
            captureFileName = capturefile.Name;

            //writing directly into the file stream
            using (IRandomAccessStream convertedImageStream = await capturefile.OpenAsync(FileAccessMode.ReadWrite))
            {
                //write changes to the BitmapEncoder
                BitmapEncoder enc = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, convertedImageStream);
                enc.SetPixelData(
                    pixelFormat,
                    alpha,
                    transform.Bounds.Width,
                    transform.Bounds.Height,
                    dec.DpiX,
                    dec.DpiY,
                    pixels
                    );

                await enc.FlushAsync();
            }
        }
        CleanCapture();

        //load saved image
        LoadCapturedphoto(captureFileName);
    }

    public async void LoadCapturedphoto(string filename)
    {
        //load saved image
        StorageFolder pictureLibrary = KnownFolders.SavedPictures;
        StorageFile savedPicture = await pictureLibrary.GetFileAsync(filename);
        ImageProperties imgProp = await savedPicture.Properties.GetImagePropertiesAsync();
        var savedPictureStream = await savedPicture.OpenAsync(FileAccessMode.Read);

        //set image properties and show the taken photo
        bitmap = new WriteableBitmap((int)imgProp.Width, (int)imgProp.Height);
        await bitmap.SetSourceAsync(savedPictureStream);
        takenImage.Source = bitmap;
        takenImage.Visibility = Visibility.Visible;
    }



推荐答案



您好GabrielF7,


Hi  GabrielF7,

感谢您在此发布。

关于开发通用Windows应用的案例,我将其移至< a href ="https://social.msdn.microsoft.com/Forums/windowsapps/en-US/home?forum=wpdevelop">开发通用Windows应用论坛以获得合适的帮助。

For your case about Developing Universal Windows apps, I will move it to Developing Universal Windows apps forum for suitable help.

您的理解与合作将不胜感激。

Your understanding and cooperation will be grateful.



最好的问候,


Best Regards,

Yohann Lu

Yohann Lu


这篇关于Windows Phone C#位图图像调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆