Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am getting a parameter invalid exception while retrieving an image (error only occurs on Win7 but working fine in XP OS)

Here is my code

C#
Image _image = null;
ImageConverter imgConverter = null;
_image = imgConverter.ConvertFrom(pItem.FrontImage) as System.Drawing.Image; //pItem.FrontImage is Byte[]


I have tried to use
C#
MemoryStream ms = new MemoryStream(pItem.FrontImage);
ms.Write(pItem.FrontImage, 0, pItem.FrontImage.Length);
_image = Image.FromStream((Stream)ms);


but no use.

Can you please help me?

Complete error:

XML
System.ArgumentException: Parameter is not valid.  
at System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement, Boolean validateImageData)  
at System.Drawing.Image.FromStream(Stream stream)



is there any other way to convert image from Byte[] without using FromStream.
I have tried to save the Image with File.WriteAllBytes but no use (Image is showing as corrupted).
Posted
Updated 20-Mar-14 22:29pm
v2
Comments
Raul Iloc 21-Mar-14 4:01am    
I saw that you are trying use an object ImageConvertor to covert your image and there is your second block?
What exactly are you trying to do? To save the image into an Image object (in memory) or to save it into a file (by using FileStream) ?
Rakesh Devarasetty 21-Mar-14 5:10am    
I will use Image object to write the Image in PDF .

Try this:
C#
// requires using System.IO
using (MemoryStream ms = new MemoryStream(pItem.FrontImage))
{
    _image = Image.FromStream(ms);
}
If this does not work, then put a break-point in your code on the line: Image _image = null; and then single-step using F11. Note where any error occurs, and post where the error occurred here in your original question.
 
Share this answer
 
v2
You get this message when stream is null or when stream doesn't contain valid image data.
This line of code is unnecessary as you have forwarded image data directly via constructor:
C#
ms.Write(pItem.FrontImage, 0, pItem.FrontImage.Length);

so try this:
C#
MemoryStream ms = new MemoryStream(pItem.FrontImage);
_image = Image.FromStream(ms,true,true);
 
Share this answer
 
I have tried with all the solutions you have mentioned .All are not useful for me .We are getting because of Multi Page Tiff Image .Same Image can be working fine with Windows Xp so we cannt think this is not a valid image .Byte array is not null value too.FromStream is not working .Please let me know any other solution .I have already tried the ways and means you have mentioned .
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900