groege / PdfSharpCore

PdfSharp port NetCore
47 stars 13 forks source link

Adding Image cause an System.NullReferenceException #16

Open Markus1397 opened 6 years ago

Markus1397 commented 6 years ago

When ever I try to add a Image my program always crash. There is no difference if I use ImageSource or XImage and also if I use FromBinary,FromFile or FromStream. Everytime I get (nearly) the same Exception. Object reference not set to an instance of an object. In case of using ImageSource.FromBinary the next line is:

at MigraDocCore.DocumentObjectModel.MigraDoc.DocumentObjectModel.Shapes.ImageSource.FromBinary(String name, Func1 imageSource, Nullable1 quality)

Before opening the file I check if the file is existing with System.IO.File.Exists; Im using .Net Core 2.0, with Visual Studio Community on Mac OS.

groege commented 6 years ago

Did you set ImageSource.ImageSourceImpl?

On Jan 30, 2018 1:49 PM, "Markus Kaufmann" notifications@github.com wrote:

When ever I try to add a Image my program always crash. There is no difference if I use ImageSource or XImage and also if I use FromBinary,FromFile or FromStream. Everytime I get (nearly) the same Exception. Object reference not set to an instance of an object. In case of using ImageSource.FromBinary the next line is:

at MigraDocCore.DocumentObjectModel.MigraDoc.DocumentObjectModel.Shapes.ImageSource.FromBinary(String name, Func1 imageSource, Nullable1 quality)

Before opening the file I check if the file is existing with System.IO.File.Exists; Im using .Net Core 2.0, with Visual Studio Community on Mac OS.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/groege/PdfSharpCore/issues/16, or mute the thread https://github.com/notifications/unsubscribe-auth/AOoWRkRJOA9-cX32EVv36KcZUJ7SpwxWks5tPw_GgaJpZM4RyRoZ .

Markus1397 commented 6 years ago

Yes I did. using(FileStream fs = info.OpenRead())
 {
 fs.Read(bytesOfImg,0,(int)info.Length);
 }
 IImageSource imgSource = ImageSource.FromBinary(info.Name,()=>bytesOfImg);

groege commented 6 years ago

That is not what i ment,

https://github.com/groege/PdfSharpCore/blob/a429b03519d4290096118642ebf5e536652aba74/PdfSharpCore.Test.Uwp/ImageSourceUnitTest.cs Take a look at the TestSetup Method.

On Tue, Feb 6, 2018 at 10:27 AM, Markus Kaufmann notifications@github.com wrote:

Yes I did. using(FileStream fs = info.OpenRead()) { fs.Read(bytesOfImg,0,(int)info.Length); } IImageSource imgSource = ImageSource.FromBinary(info. Name,()=>bytesOfImg);

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/groege/PdfSharpCore/issues/16#issuecomment-363362264, or mute the thread https://github.com/notifications/unsubscribe-auth/AOoWRstCginNBLSQZxb_8oTM7fa33Heaks5tSBsXgaJpZM4RyRoZ .

groege commented 6 years ago

Depending on the Platform you'll have to set a proper Implementation

On Tue, Feb 6, 2018 at 10:54 AM, Hans-Georg Haberl haberl.george@gmail.com wrote:

That is not what i ment,

https://github.com/groege/PdfSharpCore/blob/a429b03519d4290096118642ebf5e5 36652aba74/PdfSharpCore.Test.Uwp/ImageSourceUnitTest.cs Take a look at the TestSetup Method.

On Tue, Feb 6, 2018 at 10:27 AM, Markus Kaufmann <notifications@github.com

wrote:

Yes I did. using(FileStream fs = info.OpenRead()) { fs.Read(bytesOfImg,0,(int)info.Length); } IImageSource imgSource = ImageSource.FromBinary(info.Na me,()=>bytesOfImg);

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/groege/PdfSharpCore/issues/16#issuecomment-363362264, or mute the thread https://github.com/notifications/unsubscribe-auth/AOoWRstCginNBLSQZxb_8oTM7fa33Heaks5tSBsXgaJpZM4RyRoZ .

groege commented 6 years ago

By extending ImageSource you could also implement it on your own...

On Tue, Feb 6, 2018 at 10:54 AM, Hans-Georg Haberl haberl.george@gmail.com wrote:

Depending on the Platform you'll have to set a proper Implementation

On Tue, Feb 6, 2018 at 10:54 AM, Hans-Georg Haberl < haberl.george@gmail.com> wrote:

That is not what i ment,

https://github.com/groege/PdfSharpCore/blob/a429b03519d42900 96118642ebf5e536652aba74/PdfSharpCore.Test.Uwp/ImageSourceUnitTest.cs Take a look at the TestSetup Method.

On Tue, Feb 6, 2018 at 10:27 AM, Markus Kaufmann < notifications@github.com> wrote:

Yes I did. using(FileStream fs = info.OpenRead()) { fs.Read(bytesOfImg,0,(int)info.Length); } IImageSource imgSource = ImageSource.FromBinary(info.Na me,()=>bytesOfImg);

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/groege/PdfSharpCore/issues/16#issuecomment-363362264, or mute the thread https://github.com/notifications/unsubscribe-auth/AOoWRstCginNBLSQZxb_8oTM7fa33Heaks5tSBsXgaJpZM4RyRoZ .

gtaylor44 commented 6 years ago

Do you have implementations of ImageSourceImpl for each platform? Or is it up to us?

Default System.NullReferenceException is a bit confusing. Notes on setting font source impl are there but no documentation for image source impl.

groege commented 6 years ago

Yeah, didn't get to update the doc... I'm doing this project just on the side for my job... (put it on github in the hopes others will chime in though I don't really have any more time for it since I'm swamped with deadlines...) What platforms do you need? If it's Android, there is an Android project, another one for UWP, IOS ist not implemented... Or you could use ImageSharp (which was not performant enough at the time of implementation) which will work on all plaforms since it's implemented in c#... Though I'd write a new implementation for this as well since ImageSharp was still in alpha when I implemented it, as far as I understand they did some major changes an enhancements (maybe the performance is now better as well?) br

On Fri, Feb 9, 2018 at 5:40 PM, Greg Taylor notifications@github.com wrote:

Do you have implementations of ImageSourceImpl for each platform? Or is it up to us?

Default System.NullReferenceException is a bit confusing. Notes on setting font source impl are there but no documentation for image source impl.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/groege/PdfSharpCore/issues/16#issuecomment-364487304, or mute the thread https://github.com/notifications/unsubscribe-auth/AOoWRrcJqPRykZ0ft6aFaugMKlz4L5MJks5tTHUDgaJpZM4RyRoZ .

groege commented 6 years ago

So anyone please feel free to chime in!

On Fri, Feb 9, 2018 at 7:07 PM, Hans-Georg Haberl haberl.george@gmail.com wrote:

Yeah, didn't get to update the doc... I'm doing this project just on the side for my job... (put it on github in the hopes others will chime in though I don't really have any more time for it since I'm swamped with deadlines...) What platforms do you need? If it's Android, there is an Android project, another one for UWP, IOS ist not implemented... Or you could use ImageSharp (which was not performant enough at the time of implementation) which will work on all plaforms since it's implemented in c#... Though I'd write a new implementation for this as well since ImageSharp was still in alpha when I implemented it, as far as I understand they did some major changes an enhancements (maybe the performance is now better as well?) br

On Fri, Feb 9, 2018 at 5:40 PM, Greg Taylor notifications@github.com wrote:

Do you have implementations of ImageSourceImpl for each platform? Or is it up to us?

Default System.NullReferenceException is a bit confusing. Notes on setting font source impl are there but no documentation for image source impl.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/groege/PdfSharpCore/issues/16#issuecomment-364487304, or mute the thread https://github.com/notifications/unsubscribe-auth/AOoWRrcJqPRykZ0ft6aFaugMKlz4L5MJks5tTHUDgaJpZM4RyRoZ .

gtaylor44 commented 6 years ago

I just found this implementation in the repository, which works for my platform (.net core 2.0)

PdfSharpCore/PdfSharpCore.ImageSharp/ImageSharpImageSource.cs

gtaylor44 commented 6 years ago

I'm using the latest ImageSharp library but I think it's still a bit buggy. Doesn't handle transparency very well when importing from png format.

groege commented 6 years ago

Ok ty, So seems like to need to implement the missing platforms you want to use. Would you be so kind and send a pull request for the platforms, so others will be able to use them?

On Fri, Feb 9, 2018 at 7:14 PM, Greg Taylor notifications@github.com wrote:

I'm using the latest ImageSharp library but I think it's still a bit buggy. Doesn't handle transparency very well when importing from png format.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/groege/PdfSharpCore/issues/16#issuecomment-364513688, or mute the thread https://github.com/notifications/unsubscribe-auth/AOoWRme_C40JmC6YDDwHmlhBgnHFHWr0ks5tTIr7gaJpZM4RyRoZ .

dobestar commented 3 years ago

Hi, I am trying to do this on a .net core web app, how do I set the ImageSourceImpl so I can set ImageSource.FromFile?