gpt4 book ai didi

c# - Windows 手机图片框

转载 作者:太空狗 更新时间:2023-10-30 01:04:17 25 4
gpt4 key购买 nike

我正在用 C# 开发 Windows Phone 8.1 应用程序。我正在用相机拍照。图片然后保存在设备上,我试图在图片框中显示它。我已经在 HTC 手机上测试过,效果很好,但是当我在诺基亚 Lumia 上尝试时,图片永远不会加载。有谁知道如何解决这个问题?

这是我用来拍照的代码:

    private void snap_task_Click(object sender, EventArgs e)
{
cameraCaptureTask = new CameraCaptureTask();
cameraCaptureTask.Completed += cameraCaptureTask_Completed;
cameraCaptureTask.Show();

}

void cameraCaptureTask_Completed(object sender, PhotoResult e)
{
if (e.TaskResult == TaskResult.OK)
{
NavigationService.Navigate(new Uri("/Slika.xaml?fotka=" + e.OriginalFileName, UriKind.Relative));

}
}

这是我尝试加载图片的代码。

    public Slika()
{
InitializeComponent();
string slika = string.Empty;
string slika2 = string.Empty;
this.Loaded += (s, e) =>
{

if (NavigationContext.QueryString.TryGetValue("fotka", out slika))
{

putanja = slika; /*"/Resources/" + slika + ".png";/**/

int x = putanja.Length;

if (x == 1)
{
putanja = "/Resources/" + putanja + ".png";
uriPutanja = new Uri(putanja, UriKind.Relative);
fotka = new BitmapImage(uriPutanja);
}
else
{
uriPutanja = new Uri(putanja, UriKind.Relative);
porukaTextBox.Text = putanja;
fotka = new BitmapImage(uriPutanja);
}
}
img1.Source = fotka;

};

}

附言

从本地资源加载在两部手机上都能正常工作,它只是 if 的“其他”部分导致诺基亚出现问题。

最佳答案

您正在将图像保存在手机的相机胶卷文件夹中,请尝试将其保存在存储卡上并尝试是否可行(您只需在手机设置中更改它并说将新照片保存在SD 卡)如果可行,请尝试使用 PhotoChooserTask 获取图像。希望以下代码对您有所帮助:

    using Microsoft.Phone.Tasks;
using System.IO;
using System.Windows.Media.Imaging;
...
PhotoChooserTask selectphoto = null;
private void button1_Click(object sender, RoutedEventArgs e)
{
selectphoto = new PhotoChooserTask();
selectphoto.Completed += new EventHandler(selectphoto_Completed);
selectphoto.Show();
}
void selectphoto_Completed(object sender, PhotoResult e)
{
if (e.TaskResult == TaskResult.OK)
{
BinaryReader reader = new BinaryReader(e.ChosenPhoto);
image1.Source = new BitmapImage(new Uri(e.OriginalFileName));
}
}

关于c# - Windows 手机图片框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24104074/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com