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