[WP8.1]如何使用Windows Phone 8.1替换此Windows Phone 8代码 - 将位图转换为Base64 [英] [WP8.1]How do I replace this Windows Phone 8 code with Windows Phone 8.1 - Converting a Bitmap to Base64

查看:77
本文介绍了[WP8.1]如何使用Windows Phone 8.1替换此Windows Phone 8代码 - 将位图转换为Base64的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码将位图图像转换为Windows Phone 8中的Base64字符串。但是当我在Windows 8.1中使用相同的东西时,我得到一个错误,说明命名空间不可用,这是&span; System.Windows.Media.Imaging
。这是代码,如何在Windows Phone 8.1中使用它?

 public string GetBase64Encoding(BitmapImage imageUrl)
{
byte [] bytearray = null;
using(MemoryStream ms = new MemoryStream())
{
if(imageUrl == null)
{

}
$ else
{
WriteableBitmap wbitmp = new WriteableBitmap((BitmapImage)imageUrl);

wbitmp.SaveJpeg(ms,46,38,0,100);

bytearray = ms.ToArray();
}
}
string str = Convert.ToBase64String(bytearray);

return str;
}





Dileepa S. Rajapaksa

---------------------------------

见习开发人员

微软,斯里兰卡


----------------

Twitter:@dsrajapaksa

博客:http://www.dileepatech.net

解决方案

您好astrodileepa,


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

请阅读粘贴帖子,特别是  发布指南:subje ct行代码   已知的
Windows 10 SDK和工具的问题 
 



>>但是当我在Windows 8.1中使用相同的东西时,我收到一个错误,说明命名空间不可用,这是  System.Windows.Media.Imaging。


是的,
SaveJpeg
是一个扩展Windows Phone Silverlight应用程序中的方法,它在WinRT应用程序中不可用。在WinRT应用中,我们可以使用

BitmapEncoder
类来帮助我们实现将BitmapImage转换为Base64字符串。有关更多信息,请尝试在此处参考@Jerry Nixon的博客:

http://blog.jerrynixon.com/2014/11/reading-and-writing-base64-in-windows.html  。


最诚挚的问候,

Amy Peng






I used the following code to convert a Bitmap image to a Base64 string in Windows Phone 8. But when I use the same thing in Windows 8.1 I got an error saying the namespace not available which is System.Windows.Media.Imaging . This is the code and how do I use this in Windows Phone 8.1 ?

  public string GetBase64Encoding(BitmapImage imageUrl)
            {
            byte[] bytearray = null;
            using (MemoryStream ms = new MemoryStream())
                {
                if (imageUrl == null)
                    {

                    }
                else
                    {
                    WriteableBitmap wbitmp = new WriteableBitmap((BitmapImage)imageUrl);

                    wbitmp.SaveJpeg(ms, 46, 38, 0, 100);

                    bytearray = ms.ToArray();
                    }
                }
            string str = Convert.ToBase64String(bytearray);

            return str;
            }


Dileepa S. Rajapaksa
---------------------------------
Trainee Developer
Microsoft, Sri Lanka

----------------
Twitter : @dsrajapaksa
Blog : http://www.dileepatech.net

解决方案

Hi astrodileepa,

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  

>>But when I use the same thing in Windows 8.1 I got an error saying the namespace not available which is System.Windows.Media.Imaging .

Yes, the SaveJpeg is an extension method in Windows Phone Silverlight app and it is not available in WinRT app. In WinRT app we can use the BitmapEncoder class to help us implement converting a BitmapImage to the Base64 string. For more information, please try to refer to the @Jerry Nixon's Blog in here:
http://blog.jerrynixon.com/2014/11/reading-and-writing-base64-in-windows.html .

Best Regards,
Amy Peng



这篇关于[WP8.1]如何使用Windows Phone 8.1替换此Windows Phone 8代码 - 将位图转换为Base64的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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