473,327 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 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 5122
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: CanyonJ | last post by:
I've been running into a frustrating problem for a while now. I use image.FromStream to open a tif, then perform some drawstring methods, and then save the file again. The tiffs are in 1 bit per...
1
by: DotNetJunkies User | last post by:
i am using a dll that places an image data in memory and returns to me two wariable long P1 and long P2 i am using C# P1 is the memory address and P2 is the number of bytes written i want to place...
6
by: Peder Y | last post by:
Surely, anyone can read it's attributes and methods... Now, how does Image store the image data? How does it discern between e.g. jpg, gif and bmp. Does it know it's own size, or does one need to...
4
by: Detlef Huettenbach | last post by:
I was trying to convert a Windows Forms prototype application to an ASP.NET solution that makes use of loading data streams into the Image Web/Windows control. For WinForms no problem. However in...
6
by: David W. Simmonds | last post by:
I know that I can create an Image object by using a path like C:\MyPictures\pic.jpg, but how can I create an Image object by using a path like /MyPictures/pic.jpg where the path is relative to the...
0
by: Oleg Ogurok | last post by:
Hi all, I'm having this problem. I have a 50x50 GIF image with a transparent background. I'm trying to resize it to 25x25 using GDI+ capabilities. With Windows Forms' Image control, the image...
9
by: Tom John | last post by:
Hi I am storing images in an access database, based on an MSDN article. The code i use to store is as follows: <code> 'Create the command object Dim command As New...
1
by: halise irak via .NET 247 | last post by:
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...
2
by: Patrick F | last post by:
Hi, i have a resourcefile with my project that contains a jepg image. Now i want to retrive that image to a Image m_Image in my program. Whats the best way to do this?
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.