471,336 Members | 1,294 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

ArgumentException @ Image.FromStream(stream)

I get an "ArgumentException: Invalid parameter used at

System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement)"

exception. it is too ridicilious to get such an exception, can anyone see what

might cause that exception?

(By the way, i am trying to throw the header part of the image away and extract only
the image data)

the related source code is shown below:
private void button1_Click(object sender, System.EventArgs e)
{

string file_name = @"C:/...\IM1";
FileStream fs = new FileStream(file_name, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);

//BinaryReader br = new BinaryReader(File.OpenRead("C:/.../IM1"));
try
{
int numbytes = 140672 ;

int offset = 9600 ;

int totbytes=0;

byte[] bytearr = new byte[numbytes];

while( totbytes < (numbytes-offset) )
{
int i = br.Read(bytearr, offset,numbytes-offset) ;

totbytes+=i;
}

MemoryStream ms = new MemoryStream (bytearr,0,bytearr.Length) ;

Image img = Image.FromStream(ms,true);

//picbox.Image = new Bitmap(ms);

picbox.BackgroundImage = img ;
br.Close();
ms.Close();

}

catch( Exception exc )
{
textbox.Text = exc.ToString();
}

}

--------------------------------
From: halise irak

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>Q6akrCogcUeY5gT7XPRQBA==</Id>
Jul 21 '05 #1
1 4986
How do you think the FromImage() method will recognize the bitmap type if
you throw away the header?
"halise irak via .NET 247" <an*******@dotnet247.com> schrieb im Newsbeitrag
news:#s**************@TK2MSFTNGP12.phx.gbl...
I get an "ArgumentException: Invalid parameter used at

System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement)"
exception. it is too ridicilious to get such an exception, can anyone see what
might cause that exception?

(By the way, i am trying to throw the header part of the image away and extract only

the image data)

the related source code is shown below:
private void button1_Click(object sender, System.EventArgs e)
{

string file_name = @"C:/...\IM1";
FileStream fs = new FileStream(file_name, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fs);

//BinaryReader br = new BinaryReader(File.OpenRead("C:/.../IM1"));
try
{
int numbytes = 140672 ;

int offset = 9600 ;

int totbytes=0;

byte[] bytearr = new byte[numbytes];

while( totbytes < (numbytes-offset) )
{
int i = br.Read(bytearr, offset,numbytes-offset) ;

totbytes+=i;
}

MemoryStream ms = new MemoryStream (bytearr,0,bytearr.Length) ;

Image img = Image.FromStream(ms,true);

//picbox.Image = new Bitmap(ms);

picbox.BackgroundImage = img ;
br.Close();
ms.Close();

}

catch( Exception exc )
{
textbox.Text = exc.ToString();
}

}

--------------------------------
From: halise irak

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>Q6akrCogcUeY5gT7XPRQBA==</Id>

Jul 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by DotNetJunkies User | last post: by
6 posts views Thread by Peder Y | last post: by
4 posts views Thread by Detlef Huettenbach | last post: by
6 posts views Thread by David W. Simmonds | last post: by
reply views Thread by Oleg Ogurok | last post: by
1 post views Thread by halise irak via .NET 247 | last post: by
2 posts views Thread by Patrick F | last post: by

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.