473,554 Members | 3,241 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Conten tType = "image/jpeg";

// get byte array's length
int ArraySize = new int();
ArraySize = byteData.GetUpp erBound(0);

// put into memorystream and instantiate Image object
MemoryStream memStream = new MemoryStream();
memStream.Write (byteData,0,Arr aySize);
System.Drawing. Image myImg =
System.Drawing. Image.FromStrea m(memStream);
memStream.Close ();
memStream = null;

// prepare for display - debug showed correct FrameDimension used
System.Drawing. Imaging.FrameDi mension fDimension;
fDimension = new System.Drawing. Imaging.FrameDi mension(myImg.F rameDimensionsL ist[0]);

// just display the first page in TIFF, or display single-page TIFF
try {
myImg.SelectAct iveFrame(fDimen sion,0);
myImg.Save(Resp onse.OutputStre am,
System.Drawing. Imaging.ImageFo rmat.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 5858
I believe bitmaps need to save to seekable streams

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

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.goo gle.com...
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.Conten tType = "image/jpeg";

// get byte array's length
int ArraySize = new int();
ArraySize = byteData.GetUpp erBound(0);

// put into memorystream and instantiate Image object
MemoryStream memStream = new MemoryStream();
memStream.Write (byteData,0,Arr aySize);
System.Drawing. Image myImg =
System.Drawing. Image.FromStrea m(memStream);
memStream.Close ();
memStream = null;

// prepare for display - debug showed correct FrameDimension used
System.Drawing. Imaging.FrameDi mension fDimension;
fDimension = new System.Drawing. Imaging.FrameDi mension(myImg.F rameDimensionsL ist[0]);
// just display the first page in TIFF, or display single-page TIFF
try {
myImg.SelectAct iveFrame(fDimen sion,0);
myImg.Save(Resp onse.OutputStre am,
System.Drawing. Imaging.ImageFo rmat.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.enso ft-software.com> wrote in message news:<Oh******* *******@TK2MSFT NGP10.phx.gbl>. ..
I believe bitmaps need to save to seekable streams

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

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.goo gle.com...
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.Conten tType = "image/jpeg";

// get byte array's length
int ArraySize = new int();
ArraySize = byteData.GetUpp erBound(0);

// put into memorystream and instantiate Image object
MemoryStream memStream = new MemoryStream();
memStream.Write (byteData,0,Arr aySize);
System.Drawing. Image myImg =
System.Drawing. Image.FromStrea m(memStream);
memStream.Close ();
memStream = null;

// prepare for display - debug showed correct FrameDimension used
System.Drawing. Imaging.FrameDi mension fDimension;
fDimension = new

System.Drawing. Imaging.FrameDi mension(myImg.F rameDimensionsL ist[0]);

// just display the first page in TIFF, or display single-page TIFF
try {
myImg.SelectAct iveFrame(fDimen sion,0);
myImg.Save(Resp onse.OutputStre am,
System.Drawing. Imaging.ImageFo rmat.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.ToByt eArray() then throw that at
Response.Output Stream.WriteByt es()
--
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.goo gle.com...
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.enso ft-software.com> wrote in message

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

Write to a memory stream first, then byte copy out to Response.Output Stream
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.goo gle.com...
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.Conten tType = "image/jpeg";

// get byte array's length
int ArraySize = new int();
ArraySize = byteData.GetUpp erBound(0);

// put into memorystream and instantiate Image object
MemoryStream memStream = new MemoryStream();
memStream.Write (byteData,0,Arr aySize);
System.Drawing. Image myImg =
System.Drawing. Image.FromStrea m(memStream);
memStream.Close ();
memStream = null;

// prepare for display - debug showed correct FrameDimension used
System.Drawing. Imaging.FrameDi mension fDimension;
fDimension = new

System.Drawing. Imaging.FrameDi mension(myImg.F rameDimensionsL ist[0]);

// just display the first page in TIFF, or display single-page TIFF
try {
myImg.SelectAct iveFrame(fDimen sion,0);
myImg.Save(Resp onse.OutputStre am,
System.Drawing. Imaging.ImageFo rmat.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
12285
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: ---------------------------------------------------------------------- private sub MakeTiff dim imgSource as new bitmap(strTifSourceFile)
0
1480
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+' For 8bit multiframe TIFF-file it is working. Does anybody know if bitmap class supports 16bit multiframe TIFF files?
1
16219
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 System.Drawing.Image.Save" error. public void addAnnotationStampOnImage() { string strStamp = Path.GetFileNameWithoutExtension(_ImageFileName); Size dSize;...
0
1083
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 any other image type, but, when I run into the tiff I get a generic gdi+ error. How do you send the entire tiff image to the...
5
5971
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 TIFF to several PNG files this causes a problem, becuase the resulting image is (the page to the far left and a lot of black space surrounding it and...
5
14980
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
4624
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 extracts the CCITT-frames correct, but the second, fourth, etc. frames causes a general GDI+ error. Hope someone can help!
10
10683
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 return the combined tif image object. Thnks in advance Rinu G P
3
3309
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); //Stmt Correct where profile is class if (Data != null)
0
7787
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8029
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7551
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6131
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5147
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3539
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1121
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
831
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.