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 3 5873
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
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
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
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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)
|
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?
|
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;
Image iMulti = Image.FromFile(_ImageFileName);
|
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 response.outputstream???
TIA,
|
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 a filesize that is larger than needed.
Any ideas?
| |
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
|
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!
|
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
|
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)
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 most users, this new feature is actually very convenient. If you want to control the update process,...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |