[UWP]图像源在手机上工作但不在桌面上工作 [英] [UWP]Image Source working on Mobile but not on Desktop

查看:70
本文介绍了[UWP]图像源在手机上工作但不在桌面上工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的,


我在创建UWP应用时遇到了非常疯狂的影响。我有一个针对Windows 10版本的应用程序  10.586与MinVersion 10.240。该应用程序的一个xaml页面具有"图像"页面。控制,其具有"来源"。 xaml文件中字符串
定义的属性。 Source指向本地服务器上的jpg文件("http://192.168.1.3/blablabla.jpg"")。当我在支持开发人员的Lumia 950上尝试应用程序时(不是Insider慢速/快速响铃,高效版本14393.321)我可以看到图像为
我会期待它。但是,当我在笔记本电脑上的Windows 10桌面上直接启动应用程序以开发安装了VS2015的应用程序时,我会执行
NOT 查看图像(在版本14393.351上运行)。 Lumia 950和笔记本电脑都在同一个WLAN网络中,所以它不能成为服务器从笔记本电脑访问的问题 - 顺便说一句:在Edge浏览器中直接使用
时,源URL正在使用笔记本电脑。并且:当我在同一台笔记本电脑上的移动模拟器(10.0.10586.0 WVGA 4英寸512mb)中启动应用程序时,显示了图像
IS 。因此,防火墙等没有影响,因为那时移动仿真器也不会显示图像(我猜仿真器与主机上的应用程序保持相同的防火墙规则)。


任何人都可以解释我在桌面应用程序的系统设置中出错了吗?或者,如果我的设置没有任何问题,为什么UWP中的移动和桌面之间存在这样的差异?如何解决它?


谢谢和亲切的问候,

Gerhard

解决方案

嗨Gerhard Seeber,


如果uri是正确的,它会显示在图片上。 您是否使用网络服务器进行测试? 


另请尝试使用设置该源的代码。是否会抛出任何异常? 


例如:

< Grid Background =" {ThemeResource ApplicationPageBackgroundThemeBrush}" ;> 
< Image Name =" MyImage"宽度= QUOT; 500"高度= QUOT; 500">< /图像>
< Button Content ="点击"点击= QUOT; Button_Click">< /按钮>
< / Grid>

代码背后:

 private void Button_Click(object sender,RoutedEventArgs e)
{
var defaultImageUri = new Uri(" http://192.168.1.3/blablabla.jpg");

var bitmapImage = new BitmapImage(){UriSource = defaultImageUri};

bitmapImage.ImageFailed + = BitmapImage_ImageFailed;
MyImage.Source = bitmapImage;
}

private void BitmapImage_ImageFailed(object sender,ExceptionRoutedEventArgs e)
{
Debug.WriteLine(e.ErrorMessage);
}

最好的问候,


Jayden Gu


Dear all,

I have encountered a very crazy effect on creating UWP app. I have an app targeting Windows 10 version 10.586 with MinVersion 10.240. One xaml page of the app has a "Image" Control, which has the "Source" property defined by string in the xaml file. The Source is pointing to a jpg file on a local server ("http://192.168.1.3/blablabla.jpg"). When I try the app on my developer-enabled Lumia 950 (not Insider slow/fast ring, productive Version 14393.321) I can see the Image as I would expect it. But when I start the app directly on my Windows 10 Desktop on my Laptop for developing the app with installed VS2015 I do NOT see the Image (running on Version 14393.351). Both the Lumia 950 and the Laptop are in the same WLAN Network, so it cannot be an issue with accessibility of the server from Laptop - BTW: the Source URL is working on Laptop when used directly in Edge browser. And: when I start the app in the Mobile Emulator (10.0.10586.0 WVGA 4 Inch 512mb) on the same Laptop the Image IS shown. So, there is no influence from Firewall etc., because then the Mobile Emulator would not Show the Image, too (I guess the Emulators are stick to the same Firewall rules than apps on the host machine).

Can anyone explain what I have made wrong on my System Setup for Desktop apps? Or, if there is nothing wrong with my Setup, why is there such a discrepancy within UWP between Mobile and Desktop and what will be done to solve it?

Thanks and kind regards,
Gerhard

解决方案

Hi Gerhard Seeber,

It seems if the uri is right, it will show on the Image. Have you use the web server to test that? 

Also please try to use the code behind to set that source. Does it throw any exception? 

For example:

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Image Name="MyImage" Width="500" Height="500"></Image>
    <Button Content="Click" Click="Button_Click"></Button>
</Grid>

Code behind:

private void Button_Click(object sender, RoutedEventArgs e)
{
    var defaultImageUri = new Uri("http://192.168.1.3/blablabla.jpg");

    var bitmapImage = new BitmapImage() { UriSource = defaultImageUri };

    bitmapImage.ImageFailed += BitmapImage_ImageFailed;
    MyImage.Source = bitmapImage;
}

private void BitmapImage_ImageFailed(object sender, ExceptionRoutedEventArgs e)
{
    Debug.WriteLine(e.ErrorMessage);
}

Best Regards,

Jayden Gu


这篇关于[UWP]图像源在手机上工作但不在桌面上工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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