![](/img/trans.png)
[英]UWP, my app crashes for the image path when built , but when I run it on the debugger it works fine
[英]Windows Phone 8.1 app to share image - works fine on my phone with Visual Studio debugger attached, but crashes when run without the debugger
我正在尝试通过我的应用程序共享图像,当我通过Visual Studio在手机上运行该应用程序时,一切正常,但是当我尝试从手机上运行该图像时,每次单击共享按钮时该应用程序崩溃
private async void dataTransferManager_DataRequested(DataTransferManager sender, DataRequestedEventArgs args)
{
args.Request.Data.Properties.Title = "Let's Celebrate";
args.Request.Data.Properties.Description = "It's time to celebrate!";
DataRequestDeferral deferral = args.Request.GetDeferral();
try
{
var finalImg = await GenerateImage();
var folder = Package.Current.InstalledLocation;
const CreationCollisionOption option = CreationCollisionOption.ReplaceExisting;
var file = await folder.CreateFileAsync("letscelebrateshare.png", option);
var logicalDpi = DisplayInformation.GetForCurrentView().LogicalDpi;
var pixelBuffer = await finalImg.GetPixelsAsync();
using (var stream = await file.OpenAsync(FileAccessMode.ReadWrite))
{
var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, stream);
encoder.SetPixelData(
BitmapPixelFormat.Bgra8,
BitmapAlphaMode.Premultiplied,
(uint)finalImg.PixelWidth,
(uint)finalImg.PixelHeight,
logicalDpi,
logicalDpi,
pixelBuffer.ToArray());
await encoder.FlushAsync();
StorageFile logoFile =
await Package.Current.InstalledLocation.GetFileAsync("letscelebrateshare.png");
List<IStorageItem> storageItems = new List<IStorageItem>();
storageItems.Add(logoFile);
args.Request.Data.SetStorageItems(storageItems);
}
}
finally
{
deferral.Complete();
}
}
private async void bla... [..]
{
Exception exc= null;
try
{
//All your stuff
}
catch(Exception ex)
{
exc = ex;
}
if(exc!=null)
await msg.ShowAsync();
}
编辑:由于我不在C#中使用WP。 我想你可以试试看。 希望这可以帮助^^
打开文件打开选择器时,我遇到了同样的问题。 我找到了一个奇怪的解决方案。 当我在每个页面中删除导航参数并使用静态变量时,对我来说效果很好。 我想这会帮助你
如果该应用没有调试器就崩溃了,请尝试调试,并且共享目标可见到“挂起和关闭”(Visual Studio中为“生命周期事件”)。 在大多数情况下,您的应用会因为挂起并序列化数据而崩溃。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.