PdfSharpCore icon indicating copy to clipboard operation
PdfSharpCore copied to clipboard

Adding Image cause an System.NullReferenceException

Open Markus1397 opened this issue 8 years ago • 12 comments

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.

Markus1397 avatar Jan 30 '18 12:01 Markus1397

Did you set ImageSource.ImageSourceImpl?

On Jan 30, 2018 1:49 PM, "Markus Kaufmann" [email protected] 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 .

groege avatar Jan 30 '18 12:01 groege

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

Markus1397 avatar Feb 06 '18 09:02 Markus1397

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 [email protected] 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 avatar Feb 06 '18 09:02 groege

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

On Tue, Feb 6, 2018 at 10:54 AM, Hans-Georg Haberl [email protected] 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 <[email protected]

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 avatar Feb 06 '18 09:02 groege

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

On Tue, Feb 6, 2018 at 10:54 AM, Hans-Georg Haberl [email protected] 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 < [email protected]> 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 < [email protected]> 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 avatar Feb 06 '18 09:02 groege

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.

gtaylor44 avatar Feb 09 '18 16:02 gtaylor44

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 [email protected] 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 avatar Feb 09 '18 18:02 groege

So anyone please feel free to chime in!

On Fri, Feb 9, 2018 at 7:07 PM, Hans-Georg Haberl [email protected] 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 [email protected] 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 avatar Feb 09 '18 18:02 groege

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

PdfSharpCore/PdfSharpCore.ImageSharp/ImageSharpImageSource.cs

gtaylor44 avatar Feb 09 '18 18:02 gtaylor44

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.

gtaylor44 avatar Feb 09 '18 18:02 gtaylor44

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 [email protected] 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 .

groege avatar Feb 09 '18 18:02 groege

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?

dobestar avatar Jan 29 '21 10:01 dobestar