
NICK ANASTASOPOULOS
Top achievements
Rank 1
NICK ANASTASOPOULOS
asked on 29 Sep 2008, 01:44 PM
Hello everybody...
I have created a report and i need to display images. This images are in db. On the design of my report I put this code:
this.pictureBox3.Value = "=Fields.Front";
When I run my report from a Windows Form , I get the "Parameter is not valid" exception.
Please, if someone has an idea, tell me what must I do...
Thanks...
3 Answers, 1 is accepted
0
Hi NICK ANASTASOPOULOS,
Can you send us the picture that you have in the db. The error that you are getting is an indication that .NET cannot create and image from the buffer that is supplied. In order to debug the issue, we will need the exact image that gets you the error.
Sincerely yours,
Ross
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Can you send us the picture that you have in the db. The error that you are getting is an indication that .NET cannot create and image from the buffer that is supplied. In order to debug the issue, we will need the exact image that gets you the error.
Sincerely yours,
Ross
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0

rh
Top achievements
Rank 1
answered on 29 Sep 2008, 03:32 PM
This parameter is not valid issue absolutely killed me earlier this year. IMO, it is a bug in .NET in the GDI+ engine. What I finally found is that when pulling images from my DB they sometimes didn't have an encoder so I ended up writing a method to always put an encoder back in the image.
I now run all of my images through the following CheckForEncoder method. This used to check for an encoder and if it found an encoder then it wouldn't recreate the image with an encoder. However, as the comments indicate I still found issues where the image would indicate that it had an encoder yet it really wouldn't so I now always recreate the image with an encoder. Not very efficient, but way better than it breaking. The only thing that I can guess is that some of our users' cameras don't properly encode the image.
The imageData object is what I read the image data into from the DB. I store the mimetype for the image in the DB. I typically resize my images before putting them in the report so that the report isn't so huge. My resize method calls CheckForEncoder which is why I pass in an Image as the second parameter rather than directly use the byte array from the DB.
I now run all of my images through the following CheckForEncoder method. This used to check for an encoder and if it found an encoder then it wouldn't recreate the image with an encoder. However, as the comments indicate I still found issues where the image would indicate that it had an encoder yet it really wouldn't so I now always recreate the image with an encoder. Not very efficient, but way better than it breaking. The only thing that I can guess is that some of our users' cameras don't properly encode the image.
The imageData object is what I read the image data into from the DB. I store the mimetype for the image in the DB. I typically resize my images before putting them in the report so that the report isn't so huge. My resize method calls CheckForEncoder which is why I pass in an Image as the second parameter rather than directly use the byte array from the DB.
public static Image CheckForEncoder(IMS.Types.Images.Image imageData, Image image) |
{ |
Image imageToReturn = null; |
MemoryStream msWithEncoder = null; |
// RAH 6/5/2008: Determined that there are cases where an encoder is found but that |
// GDI+ still throws errors thinking that there isn't an encoder. |
// So for now we are going to always recreate the image with an encoder |
// and wait to see if there are performance issues with doing so. |
// |
//if (image.RawFormat == null || FindEncoder(image.RawFormat.Guid) == null) |
//{ |
switch (imageData.MimeType) |
{ |
case "image/pjpeg": |
case "image/jpeg": |
msWithEncoder = new MemoryStream(); |
//using (MemoryStream msWithEncoder = new MemoryStream()) |
//{ |
// need to call the Save method so it creates an image with an encoding |
// or else the report generation will fail |
image.Save(msWithEncoder, ImageFormat.Jpeg); |
imageToReturn = Image.FromStream(msWithEncoder); |
//} |
break; |
default: |
msWithEncoder = new MemoryStream(); |
//using (MemoryStream msWithEncoder = new MemoryStream()) |
//{ |
// need to call the Save method so it creates an image with an encoding |
// or else the report generation will fail |
image.Save(msWithEncoder, ImageFormat.Bmp); |
imageToReturn = Image.FromStream(msWithEncoder); |
//} |
break; |
} |
//} |
//else |
//{ |
// //imageToReturn = image; |
// imageToReturn = image.Clone() as Image; |
// ImageCodecInfo codec = FindEncoder(imageToReturn.RawFormat.Guid); |
//} |
return imageToReturn; |
} |
public static ImageCodecInfo FindEncoder(Guid guid) |
{ |
foreach (ImageCodecInfo info in ImageCodecInfo.GetImageEncoders()) |
{ |
if (info.FormatID.Equals(guid)) |
{ |
return info; |
} |
} |
return null; |
} |
0
Hello Nick,
By the way, I forgot to ask you whether you were using the latest available version, since once there was a problem connected with images and it might have been the cause. If you are using the latest version and the problem still exists, please open a separate support ticket and attach a sample report that demonstrates the described behavior.
P.S. You can try Roy's suggestion as well, since the problem might turn out to be the same as his.
Best wishes,
Ross
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
By the way, I forgot to ask you whether you were using the latest available version, since once there was a problem connected with images and it might have been the cause. If you are using the latest version and the problem still exists, please open a separate support ticket and attach a sample report that demonstrates the described behavior.
P.S. You can try Roy's suggestion as well, since the problem might turn out to be the same as his.
Best wishes,
Ross
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.