Re: ArgumentException @ Image.FromStream(stream)

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



The reason it's complaining is because you've stripped off the information
that made sense of the file.

If you're trying to just read the image bits you can probably do that but
you can't use the GDI+ codec to read a mutilated file. You'll have to do
that manually.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.





"halise irak via .NET 247" <anonymous@xxxxxxxxxxxxx> wrote in message
news:ehOkPzgPFHA.2144@xxxxxxxxxxxxxxxxxxxxxxx
>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>PxtSHYIKRUeqzHL0/4uaow==</Id>


.


Quantcast