G
Guest
I've been running into a frustrating problem for a while now. I use
image.FromStream to open a tif, then perform some drawstring methods, and
then save the file again. The tiffs are in 1 bit per pixel format, so there
is some compression going on when we save the file. Quite a few files are
opened and closed. Everything seems to work fine for a couple hours. The
only draw back is the cpu is generally at 100%. Then the code starts failing
at the FromStream method call with the "Object reference not set to an
instance of an object."
The tif resides on the machine's hard drive and looks fine. The file stream
also looks fine. I can close the process and reopen and the tiff that just
failed will now succeed. I am relying on the stream.close and the image
object to go out of scope to close the image object. I'm not calling
dispose. Maybe this is the cause of the problem problem, the machine
eventually gets in a bad state. Any help would be greatly appreciated.
using( Stream stream = File.Open( sourceFile, FileMode.Open,
FileAccess.Read, FileShare.Read ) )
{
if( stream == null )
{
throw new Exception( ... );
}
try
{
// Don't use fromFile, it puts a lock on the file and it stays locked
// long after the imageObject goes out of scope.
image = System.Drawing.Image.FromStream( stream );
}
catch( Exception ex ){...}
image.drawstring(...)
save image with 1bit-per-pixel compression
}
image.FromStream to open a tif, then perform some drawstring methods, and
then save the file again. The tiffs are in 1 bit per pixel format, so there
is some compression going on when we save the file. Quite a few files are
opened and closed. Everything seems to work fine for a couple hours. The
only draw back is the cpu is generally at 100%. Then the code starts failing
at the FromStream method call with the "Object reference not set to an
instance of an object."
The tif resides on the machine's hard drive and looks fine. The file stream
also looks fine. I can close the process and reopen and the tiff that just
failed will now succeed. I am relying on the stream.close and the image
object to go out of scope to close the image object. I'm not calling
dispose. Maybe this is the cause of the problem problem, the machine
eventually gets in a bad state. Any help would be greatly appreciated.
using( Stream stream = File.Open( sourceFile, FileMode.Open,
FileAccess.Read, FileShare.Read ) )
{
if( stream == null )
{
throw new Exception( ... );
}
try
{
// Don't use fromFile, it puts a lock on the file and it stays locked
// long after the imageObject goes out of scope.
image = System.Drawing.Image.FromStream( stream );
}
catch( Exception ex ){...}
image.drawstring(...)
save image with 1bit-per-pixel compression
}