Unable to Open Color Tiff using Image.FromStream or Bitmap.FromFile

Trips

Well-known member
Joined
Aug 7, 2010
Messages
2,788
Im having trouble opening a color .tiff. <br/><br/>Calling Image.FromStream on the .tiff throws an "invalid parameter" error. <br/><br/>Calling Bitmap.FromFile on the .tiff throws a "System.OutOfMemory" error (the file size is 647k).<br/><br/>The .tiff itself is not corrupt, I can open it using MS Picture Manager or MS Document Imaging (although when I open it using Windows Picture and Fax Viewer I get a "preview not available" message).<br/><br/>The *.tiff comes from a scanned document; when I scan the document in black & white the .tiff opens fine, this certainly has to do with it being in color.<br/><br/>I am using Atalasoft controls on the web page where the image is uploaded. I can create an ImageInfo object from the .tiff and can see from it that the .tiff is Image Type Tiff, Pixel24bppBgr, 300 dpi. <br/><br/>If anyone has source code they use to succesfully open a color .tiff I would very much appreciate seeing it.<br/><br/>Here is a console app that demonstrates my problem. Both tiffs are at 300 dpi. The black and white succeeds on all 3; the color fails on all 3. This forum does not allow posting attachments so I cannot post the actual tiffs, but I imagine any color or b&w tiff would suffice to demonstrate the issue.<br/><br/><span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small <font size=2 color="#0000ff <font size=2 color="#0000ff
static
</font></font><font size=2 color="#0000ff

</font>
<span style="font-size:x-small <span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small void<span style="font-size:x-small Main(<span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small string<span style="font-size:x-small [] args)
{
<font size=2>

</font>
<span style="color:#2b91af;font-size:x-small <span style="color:#2b91af;font-size:x-small StringBuilder<span style="font-size:x-small sb = <span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small new<span style="font-size:x-small <span style="color:#2b91af;font-size:x-small <span style="color:#2b91af;font-size:x-small StringBuilder<span style="font-size:x-small ();<font size=2>
AttemptOpenFile(
</font>
<span style="color:#a31515;font-size:x-small <span style="color:#a31515;font-size:x-small "BlackAndWhiteScan.tif"<span style="font-size:x-small ,sb);<font size=2>
AttemptOpenFile(
</font>
<span style="color:#a31515;font-size:x-small <span style="color:#a31515;font-size:x-small "ColorScan.tif"<span style="font-size:x-small , sb);<font size=2>

</font>
<span style="color:#2b91af;font-size:x-small <span style="color:#2b91af;font-size:x-small Console<span style="font-size:x-small .Write(sb.ToString());<font size=2>

</font>
<span style="color:#2b91af;font-size:x-small <span style="color:#2b91af;font-size:x-small Console<span style="font-size:x-small .ReadLine();
}
<font size=2>

</font>
<span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small private<span style="font-size:x-small <span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small static<span style="font-size:x-small <span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small void<span style="font-size:x-small AttemptOpenFile(<span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small string<span style="font-size:x-small fileName, <span style="color:#2b91af;font-size:x-small <span style="color:#2b91af;font-size:x-small StringBuilder<span style="font-size:x-small sb)
{
sb.AppendLine(fileName);
<font size=2>

</font>
<span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small try
<span style="font-size:x-small
{
<font size=2>

</font>
<span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small using<span style="font-size:x-small (<span style="color:#2b91af;font-size:x-small <span style="color:#2b91af;font-size:x-small FileStream<span style="font-size:x-small fs = <span style="color:#2b91af;font-size:x-small <span style="color:#2b91af;font-size:x-small File<span style="font-size:x-small .OpenRead(fileName))
{
<font size=2>

</font>
<span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small using<span style="font-size:x-small (<span style="color:#2b91af;font-size:x-small <span style="color:#2b91af;font-size:x-small Image<span style="font-size:x-small img = <span style="color:#2b91af;font-size:x-small <span style="color:#2b91af;font-size:x-small Image<span style="font-size:x-small .FromStream(fs)) { sb.AppendLine(<span style="color:#a31515;font-size:x-small <span style="color:#a31515;font-size:x-small "One Success"<span style="font-size:x-small ); }
}
}
<font size=2>

</font>
<span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small catch<span style="font-size:x-small (<span style="color:#2b91af;font-size:x-small <span style="color:#2b91af;font-size:x-small Exception<span style="font-size:x-small ex)
{
<font size=2>
sb.AppendLine(
</font>
<span style="color:#a31515;font-size:x-small <span style="color:#a31515;font-size:x-small "One Failed"<span style="font-size:x-small );
sb.AppendLine(ex.ToString());
}
<font size=2>

</font>
<span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small try
<span style="font-size:x-small
{
<font size=2>

</font>
<span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small using<span style="font-size:x-small (<span style="color:#2b91af;font-size:x-small <span style="color:#2b91af;font-size:x-small Image<span style="font-size:x-small img = <span style="color:#2b91af;font-size:x-small <span style="color:#2b91af;font-size:x-small Bitmap<span style="font-size:x-small .FromFile(fileName)) { sb.AppendLine(<span style="color:#a31515;font-size:x-small <span style="color:#a31515;font-size:x-small "Two Success"<span style="font-size:x-small ); }
}
<font size=2>

</font>
<span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small catch<span style="font-size:x-small (<span style="color:#2b91af;font-size:x-small <span style="color:#2b91af;font-size:x-small Exception<span style="font-size:x-small ex)
{
<font size=2>
sb.AppendLine(
</font>
<span style="color:#a31515;font-size:x-small <span style="color:#a31515;font-size:x-small "Two Failed"<span style="font-size:x-small );
sb.AppendLine(ex.ToString());
}
<font size=2>

</font>
<span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small try
<span style="font-size:x-small
{
<font size=2>

</font>
<span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small using<span style="font-size:x-small (<span style="color:#2b91af;font-size:x-small <span style="color:#2b91af;font-size:x-small FileStream<span style="font-size:x-small fs = <span style="color:#2b91af;font-size:x-small <span style="color:#2b91af;font-size:x-small File<span style="font-size:x-small .OpenRead(fileName))
{
<font size=2>

</font>
<span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small using<span style="font-size:x-small (<span style="color:#2b91af;font-size:x-small <span style="color:#2b91af;font-size:x-small Image<span style="font-size:x-small img = <span style="color:#2b91af;font-size:x-small <span style="color:#2b91af;font-size:x-small Bitmap<span style="font-size:x-small .FromStream(fs, <span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small true<span style="font-size:x-small , <span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small false<span style="font-size:x-small )) { sb.AppendLine(<span style="color:#a31515;font-size:x-small <span style="color:#a31515;font-size:x-small "Three Success"<span style="font-size:x-small ); }
}
}
<font size=2>

</font>
<span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small catch<span style="font-size:x-small (<span style="color:#2b91af;font-size:x-small <span style="color:#2b91af;font-size:x-small Exception<span style="font-size:x-small ex)
{
<font size=2>
sb.AppendLine(
</font>
<span style="color:#a31515;font-size:x-small <span style="color:#a31515;font-size:x-small "Three Failed"<span style="font-size:x-small );
sb.AppendLine(ex.ToString());
}
}

<br/>
<
Tom Regan

View the full article
 
Back
Top