T
T. Davis
In C#, I am able to successfully stream a TIFF image that comes from a
BLOB field in a database, save it to file, then convert the pages
within TIFF file into jpegs (using GDI+) and display on the web (using
ASP.NET).
However, when I generate the Image object using FromStream (passing in
the MemoryStream containing image bytes), an exception of "A generic
error occurred in GDI+" is thrown when performing the conversion/save
for display. I cannot find info on why this occurs?
Again, using FromFile works fine, and the image streamed from the DB
is fine.
-- start code snippet --
/* bytedata is a byte array holding the returned image (BLOB) */
Response.ContentType = "image/jpeg";
// get byte array's length
int ArraySize = new int();
ArraySize = byteData.GetUpperBound(0);
// put into memorystream and instantiate Image object
MemoryStream memStream = new MemoryStream();
memStream.Write(byteData,0,ArraySize);
System.Drawing.Image myImg =
System.Drawing.Image.FromStream(memStream);
memStream.Close();
memStream = null;
// prepare for display - debug showed correct FrameDimension used
System.Drawing.Imaging.FrameDimension fDimension;
fDimension = new System.Drawing.Imaging.FrameDimension(myImg.FrameDimensionsList[0]);
// just display the first page in TIFF, or display single-page TIFF
try {
myImg.SelectActiveFrame(fDimension,0);
myImg.Save(Response.OutputStream,
System.Drawing.Imaging.ImageFormat.Jpeg); // EXCEPTION IS THROWN HERE
catch (Exception err)
{
throw err;
}
finally
{
myImg.Dispose();
}
-- end code snippet --
Help, please. Thanks in advance...
TD
BLOB field in a database, save it to file, then convert the pages
within TIFF file into jpegs (using GDI+) and display on the web (using
ASP.NET).
However, when I generate the Image object using FromStream (passing in
the MemoryStream containing image bytes), an exception of "A generic
error occurred in GDI+" is thrown when performing the conversion/save
for display. I cannot find info on why this occurs?
Again, using FromFile works fine, and the image streamed from the DB
is fine.
-- start code snippet --
/* bytedata is a byte array holding the returned image (BLOB) */
Response.ContentType = "image/jpeg";
// get byte array's length
int ArraySize = new int();
ArraySize = byteData.GetUpperBound(0);
// put into memorystream and instantiate Image object
MemoryStream memStream = new MemoryStream();
memStream.Write(byteData,0,ArraySize);
System.Drawing.Image myImg =
System.Drawing.Image.FromStream(memStream);
memStream.Close();
memStream = null;
// prepare for display - debug showed correct FrameDimension used
System.Drawing.Imaging.FrameDimension fDimension;
fDimension = new System.Drawing.Imaging.FrameDimension(myImg.FrameDimensionsList[0]);
// just display the first page in TIFF, or display single-page TIFF
try {
myImg.SelectActiveFrame(fDimension,0);
myImg.Save(Response.OutputStream,
System.Drawing.Imaging.ImageFormat.Jpeg); // EXCEPTION IS THROWN HERE
catch (Exception err)
{
throw err;
}
finally
{
myImg.Dispose();
}
-- end code snippet --
Help, please. Thanks in advance...
TD