ArgumentException @ Image.FromStream(stream)

  • Thread starter halise irak via .NET 247
  • Start date
H

halise irak via .NET 247

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();
}

}
 
C

cody

How do you think the FromImage() method will recognize the bitmap type if
you throw away the header?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top