C# 无法在windows phone listview中显示捕获的图像
我试图在windows phone listview中显示捕获的图像,以便使用后台代理上载。但当cameracapturedtask完成时,该应用程序将在app.xaml.cs中停用。当我从Gallery上传图像时,同样的功能也可以正常工作。我在下面包含了我的代码。如果有任何解决方案,请提供帮助C# 无法在windows phone listview中显示捕获的图像,c#,windows-phone-8,C#,Windows Phone 8,我试图在windows phone listview中显示捕获的图像,以便使用后台代理上载。但当cameracapturedtask完成时,该应用程序将在app.xaml.cs中停用。当我从Gallery上传图像时,同样的功能也可以正常工作。我在下面包含了我的代码。如果有任何解决方案,请提供帮助 private void Camera_Click(object sender, RoutedEventArgs e) { cmb.Dismiss(); Ca
private void Camera_Click(object sender, RoutedEventArgs e)
{
cmb.Dismiss();
CameraCaptureTask cameraCapture = new CameraCaptureTask();
cameraCapture.Completed += new EventHandler<PhotoResult>(cameraCaptureTask_Completed);
cameraCapture.Show();
}
private void cameraCaptureTask_Completed(object sender, PhotoResult e)
{
if (e.TaskResult == TaskResult.OK)
{
string filename = e.OriginalFileName;
var listSplit = filename.Split('\\');
int i = listSplit.Length;
string name = listSplit[i - 1];
PhotoResult photoResult = e;
j = 1;
//sendImgRequest(name, e);
BitmapImage bmp = new BitmapImage();
bmp.SetSource(e.ChosenPhoto);
arrfilename.Add(filename);
//arrimg.Add(bmp);
arrstream.Add(e.ChosenPhoto);
arrtext.Add("Photo");
using (var isostore = IsolatedStorageFile.GetUserStoreForApplication())
{
var wb = new WriteableBitmap(bmp);
using (var isoFileStream = isostore.CreateFile(name))
wb.SaveJpeg(isoFileStream, wb.PixelWidth, wb.PixelHeight, 0, 100);
}
newimgdata.Add(new imgdata { image = bmp, text = "Photo", filename = name });
lstbox.ItemsSource = newimgdata;
}
}
private void摄影机\u单击(对象发送器,路由目标)
{
中巴.解雇(;
CameraCaptureTask cameraCapture=新建CameraCaptureTask();
cameraCapture.Completed+=新事件处理程序(cameraCaptureTask_Completed);
cameraCapture.Show();
}
私有void cameraCaptureTask_已完成(对象发送方,PhotoResult e)
{
if(e.TaskResult==TaskResult.OK)
{
字符串文件名=e.OriginalFileName;
var listSplit=filename.Split('\\');
int i=listSplit.Length;
字符串名称=listSplit[i-1];
PhotoResult PhotoResult=e;
j=1;
//sendImgRequest(姓名,e);
BitmapImage bmp=新的BitmapImage();
bmp.SetSource(e.ChosenPhoto);
添加(文件名);
//arrimg.Add(bmp);
arrstream.Add(e.ChosenPhoto);
添加文本(“照片”);
使用(var isostore=IsolatedStorageFile.GetUserStoreForApplication())
{
var wb=新的可写位图(bmp);
使用(var isoFileStream=isostore.CreateFile(名称))
SaveJpeg(isoFileStream,wb.PixelWidth,wb.PixelHeight,0100);
}
添加(新imgdata{image=bmp,text=“Photo”,filename=name});
lstbox.ItemsSource=newimgdata;
}
}
只是为了兴趣;将一个try catch
块封装整个cameraCaptureTask_Completed
函数,并检查应用程序是否仍处于停用状态。