472,371 Members | 1,586 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,371 software developers and data experts.

Displaying TIFF with ASP.NET/C# - MemoryStream throws GDI+ Generic Error

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.FrameD imensionsList[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
Nov 18 '05 #1
3 5753
I believe bitmaps need to save to seekable streams

Write to a memory stream first, then byte copy out to Response.OutputStream

HTH

--
Eric Newton
C#/ASP Application Developer
http://ensoft-software.com/
er**@cc.ensoft-software.com [remove the first "CC."]

"T. Davis" <co*****@escmag.com> wrote in message
news:6f**************************@posting.google.c om...
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.FrameD imensionsList[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

Nov 18 '05 #2
Eric -

Is MemoryStream not a seekable stream?

Also, could you elaborate on your suggestion... you suggest byte copy
out of the memory stream into an outputstream? I'm not sure I can
pass that outputstream then into the Image object, if I understand
correctly...

Thanks,
TD
"Eric Newton" <er**@cc.ensoft-software.com> wrote in message news:<Oh**************@TK2MSFTNGP10.phx.gbl>...
I believe bitmaps need to save to seekable streams

Write to a memory stream first, then byte copy out to Response.OutputStream

HTH

--
Eric Newton
C#/ASP Application Developer
http://ensoft-software.com/
er**@cc.ensoft-software.com [remove the first "CC."]

"T. Davis" <co*****@escmag.com> wrote in message
news:6f**************************@posting.google.c om...
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.FrameD imensionsList[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

Nov 18 '05 #3
MemoryStreams are seekable, unless a constructor variant is called that
forces no seeking... but in essense a MemoryStream is just a dynamically
sizing byte array.

Incidentally a Bitmap constructor can take a memory stream as a parameter

you could do a memStream.ToByteArray() then throw that at
Response.OutputStream.WriteBytes()
--
Eric Newton
C#/ASP Application Developer
http://ensoft-software.com/
er**@cc.ensoft-software.com [remove the first "CC."]

"T. Davis" <co*****@escmag.com> wrote in message
news:6f**************************@posting.google.c om...
Eric -

Is MemoryStream not a seekable stream?

Also, could you elaborate on your suggestion... you suggest byte copy
out of the memory stream into an outputstream? I'm not sure I can
pass that outputstream then into the Image object, if I understand
correctly...

Thanks,
TD
"Eric Newton" <er**@cc.ensoft-software.com> wrote in message

news:<Oh**************@TK2MSFTNGP10.phx.gbl>...
I believe bitmaps need to save to seekable streams

Write to a memory stream first, then byte copy out to Response.OutputStream
HTH

--
Eric Newton
C#/ASP Application Developer
http://ensoft-software.com/
er**@cc.ensoft-software.com [remove the first "CC."]

"T. Davis" <co*****@escmag.com> wrote in message
news:6f**************************@posting.google.c om...
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.FrameD imensionsList[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

Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Maurice Mertens | last post by:
Hello, I'm having troubles with saving a tiff-file with a certain compression and colordepth. This is the code I use: ----------------------------------------------------------------------...
0
by: Greg | last post by:
Hello, I'm trying to load a 16bit multiframe TIFF-file in a bitmap, but it doesn't work. Error message: 'System.Runtime.InteropServices.ExternalException' 'A generic error occurred in GDI+' ...
1
by: Prasad More | last post by:
Hello, I am trying to write a text on Multi-page TIFF image using C# and .NET GDI+. I have written following code to do this. When I execute this code I get "Invalid Parameter User. at...
0
by: Jared | last post by:
Please note that I posted in the framework.drawing group as well. Hello all, I want to display multipart tiff images in a web browser using the response.outputstream. I know how to do it with...
5
by: Shane Story | last post by:
I can seem to get the dimensions of a frame in a multiframe tiff. After selecting activeframe, the Width/Height is still really much larger than the page's actual dimensions. When I split a...
5
by: Sameer Gupta | last post by:
what are options for opening / handling tiff files in .Net framework ? which is the best library, namespace ? Please help Regards Sameer Gupta C# Designer & Developer Siemens UK
5
by: sascha.folville | last post by:
Hi, I've some trouble reading the containing frames of a multiframe tiff. First frame is a 1700X2400 px CCITT4, second in JPG 820x1200, third is a CCITT again ... and so on. My function...
10
by: =?Utf-8?B?UmludSBHb3BhbGFrcmlzaG5hIFBpbGxhaQ==?= | last post by:
Hi, Please help me to write a dll in C# , that will read each pages of a tiff image from a file and a memory stream object ( need two ways) and creatre a new tiff image object.The dll should...
3
by: uday1302 | last post by:
Hi Dear, Here I am trying to upload a photo. protected void LoadImage() { string UserName = Session.ToString(); byte Data = Profile.GetImageData(UserName);...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.