PdfSharp.Xamarin
PdfSharp.Xamarin copied to clipboard
Android: NullReferenceException @ Image.AsJpeg() / Document.Save()
Saving a View with Images is not working on Android
myDocument.Save() -> exception myImage.AsJpeg() -> exception myImage.AsBitmap() -> works
PDFsharp 1.50.5147 PdfSharp.Xamarin.Forms 1.0.0
System.NullReferenceException: Object reference not set to an instance of an object. at PdfSharp.Xamarin.Forms.Droid.AndroidImageSourceImpl.SaveAsJpeg (System.IO.MemoryStream ms) [0x00045] in E:\My Xamarin plugin\PdfSharp.Xamarin.Forms\PdfSharp.Xamarin.Forms\PdfSharp.Xamarin.Forms.Android\AndroidImageSourceImpl.cs:111 at PdfSharpCore.Drawing.XImage.AsJpeg () [0x00006] in <11413e5833e04920b85b1578e479c930>:0
Bug fixed:
public AndroidImageSourceImpl(string name, Func<Stream> streamSource, int quality)
{
Name = name;
_streamSource = streamSource;
_quality = quality;
using (var stream = streamSource.Invoke())
{
Orientation = Orientation.Normal;
stream.Seek(0, SeekOrigin.Begin);
var options = new Options { InJustDecodeBounds = true };
using (DecodeStream(stream, null, options))
Bitmap = BitmapFactory.DecodeStream(_streamSource.Invoke()); // bugfix
Width = Orientation == Orientation.Normal || Orientation == Orientation.Rotate180 ? options.OutWidth : options.OutHeight;
Height = Orientation == Orientation.Normal || Orientation == Orientation.Rotate180 ? options.OutHeight : options.OutWidth;
}
}
@roceh could you please take a look at this and release an update?