[WP8.1]当保存到Windows Phone 10中的隔离存储器中时,图像变得模糊 [英] [WP8.1]Image is getting blurred when saved into isolated storage in windows phone 10

查看:45
本文介绍了[WP8.1]当保存到Windows Phone 10中的隔离存储器中时,图像变得模糊的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在开发一款Windows Phone 8.1应用程序,我的应用程序需要捕获图像,当我将图像保存到隔离存储时捕获图像没有问题模糊。当应用程序在Windows Phone 8.1中运行时,图像到隔离存储工作正常。当它在Windows Phone 10中时它很模糊。我正在使用以下代码。我正在使用FileOpenPicker来选择图像。 / p>


private async void viewActivated(CoreApplicationView sender,Windows.ApplicationModel.Activation.IActivatedEventArgs args)

        {

            FileOpenPickerContinuationEventArgs args1 = args as FileOpenPickerContinuationEventArgs;


if(args1!= null)

            {

                if(args1.Files.Count == 0)返回;



                View.Activated - = viewActivated;

                StorageFile storageFile = args1.Files [0];

                var stream = await storageFile.OpenAsync(Windows.Storage.FileAccessMode.Read);



               等待IsolatedStorage.SaveImages(stream.AsStream(),directory,myFilename);

}



  public async Task< bool> SaveImages(Stream stream,string directory,string fileName)

  &NBSP; &NBSP; &NBSP; {


StorageFolder folder = null;



  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; StorageFolder localFolder = ApplicationData.Current.LocalFolder;

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; folder = localFolder;

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;试试
  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; foreach(目录中的var项目.Split('\\'))

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; folder = await folder.CreateFolderAsync(item,CreationCollisionOption.OpenIfExists);

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; catch(例外情况)

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {

$
  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }


$


$


  ; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; BitmapImage bitmapImage = new BitmapImage();

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;试试
  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {

$


  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; StorageFile file = await folder.CreateFileAsync(fileName,CreationCollisionOption.ReplaceExisting);



  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; bitmapImage.DecodePixelHeight = 500;

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;等待bitmapImage.SetSourceAsync(stream.AsRandomAccessStream());

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; // var wb = new WriteableBitmap(bitmapImage.PixelWidth,bitmapImage.PixelHeight);



  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; // if(Constants.IsCompress)

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; // {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; BitmapDecoder bmpDecoder = await BitmapDecoder.CreateAsync(stream.AsRandomAccessStream());

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; BitmapTransform trns = new BitmapTransform();

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; trns.Rotation = BitmapRotation.None;

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; trns.Flip = BitmapFlip.None;

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; PixelDataProvider pixelData = await bmpDecoder.GetPixelDataAsync(bmpDecoder.BitmapPixelFormat,BitmapAlphaMode.Premultiplied,trns,ExifOrientationMode.IgnoreExifOrientation,ColorManagementMode.ColorManageToSRgb);

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; using(var destFileStream = await file.OpenAsync(FileAccessMode.ReadWrite))

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; BitmapEncoder bmpEncoder = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId,destFileStream);
$


  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; bmpEncoder.SetPixelData(BitmapPixelFormat.Bgra8,BitmapAlphaMode.Straight,Convert.ToUInt32(bmpDecoder.OrientedPixelWidth),Convert.ToUInt32(bmpDecoder.OrientedPixelHeight),bmpDecoder.DpiX,
bmpDecoder.DpiY,pixelData.DetachPixelData());

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; await bmpEncoder.FlushAsync();

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; stream.Dispose();


 }

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; catch(例外情况)

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; string s = ex.Message;

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }


  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;返回true;






解决方案

你好Alok Varma,


欢迎
到开发通用Windows应用论坛!


请阅读粘贴帖子,尤其是

发布指南:主题行标签

Windows 10 SDK和工具的已知问题




这次我为你添加了标签,你下次需要自己添加标签。


我会用你的代码来测试它我这边。可能会有一些时间延迟。感谢您的耐心等待。如果我得到任何有用的信息,我会在这里更新。


最好的问候,


Xavier Eoro

Hi,

I am developing a windows phone 8.1 app,my app needs to capture images there is no issue in capturing images when I save the image to isolated storage its getting blurred.Saving of images to isolated storage works fine when app runs in windows phone 8.1 when it is in windows phone 10 it is blurred.I am using the following code.I am using FileOpenPicker to select an image.

private async void viewActivated(CoreApplicationView sender, Windows.ApplicationModel.Activation.IActivatedEventArgs args)
        {
            FileOpenPickerContinuationEventArgs args1 = args as FileOpenPickerContinuationEventArgs;

if (args1 != null)
            {
                if (args1.Files.Count == 0) return;

                View.Activated -= viewActivated;
                StorageFile storageFile = args1.Files[0];
                var stream = await storageFile.OpenAsync(Windows.Storage.FileAccessMode.Read);

                await isolatedStorage.SaveImages(stream.AsStream(), directory, myFilename);

}

 public async Task<bool> SaveImages(Stream stream, string directory, string fileName)
        {

StorageFolder folder = null;

            StorageFolder localFolder = ApplicationData.Current.LocalFolder;
            folder = localFolder;
            try
            {
                foreach (var item in directory.Split('\\'))
                {
                    folder = await folder.CreateFolderAsync(item, CreationCollisionOption.OpenIfExists);
                }
            }
            catch (Exception ex)
            {

            }





            BitmapImage bitmapImage = new BitmapImage();
            try
            {


                StorageFile file = await folder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);

                bitmapImage.DecodePixelHeight = 500;
                await bitmapImage.SetSourceAsync(stream.AsRandomAccessStream());
                //var wb = new WriteableBitmap(bitmapImage.PixelWidth,bitmapImage.PixelHeight);

                //if (Constants.IsCompress)
                //{
                BitmapDecoder bmpDecoder = await BitmapDecoder.CreateAsync(stream.AsRandomAccessStream());
                BitmapTransform trns = new BitmapTransform();
                trns.Rotation = BitmapRotation.None;
                trns.Flip = BitmapFlip.None;
                PixelDataProvider pixelData = await bmpDecoder.GetPixelDataAsync(bmpDecoder.BitmapPixelFormat, BitmapAlphaMode.Premultiplied, trns, ExifOrientationMode.IgnoreExifOrientation, ColorManagementMode.ColorManageToSRgb);
                using (var destFileStream = await file.OpenAsync(FileAccessMode.ReadWrite))
                {
                    BitmapEncoder bmpEncoder = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, destFileStream);

                    bmpEncoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Straight, Convert.ToUInt32(bmpDecoder.OrientedPixelWidth), Convert.ToUInt32(bmpDecoder.OrientedPixelHeight), bmpDecoder.DpiX, bmpDecoder.DpiY, pixelData.DetachPixelData());
                    await bmpEncoder.FlushAsync();
                }
                stream.Dispose();

 }
            catch (Exception ex)
            {
                string s = ex.Message;
            }

            return true;


解决方案

Hi Alok Varma,

Welcome to the Developing Universal Windows apps forum!

Please read the sticky posts, especially the Guide to posting: subject line tags and Known Issues for Windows 10 SDK and Tools


I have added tag for you this time, and you would need to add tag by yourself next time.

I would use your code to test it in my side. There might be some time delay. Appreciate your patience. If I got any useful information, I would update here.

Best Regards,

Xavier Eoro


这篇关于[WP8.1]当保存到Windows Phone 10中的隔离存储器中时,图像变得模糊的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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