选择,将图像从Photostream转换为base64,Windows Phone 8 [英] Selecting , Convert an image from Photostream into base64, Windows Phone 8

查看:94
本文介绍了选择,将图像从Photostream转换为base64,Windows Phone 8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用了一个按钮并使用 PhotoChooserTask 选择了一个图像..然后我在一个按钮上显示了它的文件名..现在我需要将该图像转换为base64并在一个按钮中显示该base64值textbox ..我不知道如何转换..任何帮助将不胜感激



I have taken a button and selected an image using PhotoChooserTask ..then i displayed its file name on a button .. now i need to convert that image into base64 and display that base64 value in a textbox.. i dont know how to convert .. Any help will be appreciated

void photoChooserTask_Completed(object sender, PhotoResult e)
        {
            if (e.TaskResult == TaskResult.OK)
            {
                //Initialise the result 
                photoStream = new MemoryStream();
                // saving (copy to stream)
                e.ChosenPhoto.CopyTo(photoStream);
                //saving original file name 
                filename = e.OriginalFileName;
                //TxtBlock.Text = e.OriginalFileName;
                var bitmapImage = new BitmapImage();
                bitmapImage.SetSource(photoStream);
                //ImageViewer.Source = bitmapImage;
                btnupload.Content = e.OriginalFileName;
            }
       }

推荐答案

Heyy ..发现它是我自己..在这里发布解决方案更多开发人员知道..这是使用 Photochoosertask 从图库中选择图像的完整解决方案,将其转换为字节,然后将字节转换为base64字符串





Heyy .. Found it my self.. Posting the sol here for further developers to know.. Here is the complete solution for selecting image from gallery using Photochoosertask ,converting that to byte and then byte to base64 string


public void photoChooserTask_Completed(object sender, PhotoResult e)
 {
     if (e.TaskResult == TaskResult.OK)
     {
         //Initialise the result
         photoStream = new MemoryStream();
         // saving (copy to stream)
         e.ChosenPhoto.CopyTo(photoStream);
         //saving original file name
         filename = e.OriginalFileName;
         //Image Filename to textbox text

         btnUpload.IsEnabled = true;

         //Convert Memory Stream To byte Array
         byte[] imgArray = new byte[e.ChosenPhoto.Length];
         e.ChosenPhoto.Read(imgArray, 0, imgArray.Length);
         // Creating Bitmap Image
         BitmapImage bitmap = new BitmapImage();
         bitmap.SetSource(e.ChosenPhoto);
         WriteableBitmap wb = new WriteableBitmap(bitmap);
         MemoryStream ms = new MemoryStream();
         wb.SaveJpeg(ms, bitmap.PixelWidth, bitmap.PixelHeight, 0, 100);
         byte[] imageBytes = ms.ToArray();
         string strimageInBase64;
         strimageInBase64 = System.Convert.ToBase64String(imageBytes);

         //print byte Array
         //StreamTextbox.Text = imgArray.ToString();

         //Just Print Byte64 to know output
         StreamTextbox.Text = strimageInBase64;
     }
 }


这篇关于选择,将图像从Photostream转换为base64,Windows Phone 8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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