The following code is meant to load an embedded GIF image resource, to be inserted into a PDF. Unfortunately, iTextSharp.text.Image.GetInstance()
generates an exception message:
Object reference not set to an instance of an object.
I believe that means something is null that shouldn't be. But stepping through the code using the Visual C# Express debugger hasn't revealed what it might be, to me.
I was wondering if a more experienced C#/iTextSharp hacker might be able to spot where I'm going wrong?
using System;
using System.IO;
using iTextSharp.text;
using iTextSharp.text.pdf;
namespace giftest
{
class Program
{
static void Main(string[] args)
{
try
{
System.IO.Stream s =
System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("giftest.clear.gif");
iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(s);
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
}
catch (Exception ex)
{
Console.WriteLine("Some sort of error occured: " + ex.Message);
Console.WriteLine();
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
}
}
}
}
/* clear.gif
* data:image/gif;base64,R0lGODlhAQABAHAAACH5BAUAAAAALAAAAAABAAEAAAICRAEAOw==
*/