我正在使用 Syncfusion 和 Xamarin Forms 即时创建 PDF。在 iOS 中一切顺利,但在 Android 中,它无法定位图像( Logo )。
跟随syncfusion PDF入门,但即使它不起作用。该图像位于android的resource/drawable中。我也将其添加到 Assets 中。
这是 xamarin 表单 iOS 中的工作代码
//Load the image
Stream imageStream = System.IO.File.OpenRead("logo.jpg");
//Load the image from the stream
PdfBitmap image = new PdfBitmap(imageStream);
不幸的是,即使这在 Android 上也不起作用
//Load the image
Stream imageStream = DependencyService.Get<ISave>().LoadFromFile(@"logo.jpg");
//Load the image from the stream
PdfBitmap image = new PdfBitmap(imageStream);
非常感谢您的帮助,因为我已经在这个问题上坚持了 3 天了。
最佳答案
进一步分析Xamarin Android中的“从drawable文件夹加载图像”,我们发现无法直接从drawable文件夹加载图像。相反,我们可以从资源中获取 if 。请查找以下代码片段了解更多详细信息,
Xamarin.Android:
var context = Android.App.Application.Context;
using (var drawable =
Xamarin.Forms.Platform.Android.ResourceManager.GetDrawable(context, fileName))
using (var bitmap = ((BitmapDrawable)drawable).Bitmap)
{
var stream = new MemoryStream();
bitmap.Compress(Bitmap.CompressFormat.Png, 100, stream);
bitmap.Recycle();
return stream.ToArray();
}
我们已经创建了相同的示例,可以从下面的链接下载,
关于c# - 同步融合 PDF : Adding image to pdf works in iOS but not in android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56110788/