Tech Talk A software developer on all things tech, and then some

25Jun/123

The image cannot be decoded. The image header might be corrupted

I was recently trying to send to Telerik's image editing control a jpeg image in a stream format. I was checking for the other types and using the appropriate format providers, but I kept getting an exception when working with JPEGs :

The image cannot be decoded. The image header might be corrupted

With the following code :

else if (extension == "jpg" || extension == "jpeg")
{
	provider = new JpegFormatProvider();
	imageEditorUI.Image = provider.Import(file);
}

So, I had looked through their documentation and a few examples, but found nothing. I then moved on to searching the C# forums on the MSDN, and came across a post where somebody was having the same message, similar issue (not using Telerik's JpegFormatProvider). Then it hit me, the reader was starting at the last position. So, I set the position to the beginning, and everything worked as expected

else if (extension == "jpg" || extension == "jpeg")
{
	provider = new JpegFormatProvider();
        stream.Position = 0; //Setting the stream to zero.
	imageEditorUI.Image = provider.Import(file);
}

Hope this helps for anybody else with the same issue.

Comments (3) Trackbacks (0)
  1. You save a lot of time. Thank you.

  2. thaaaaaaaaaaaaaaank youuuuuuuuuu


Leave a Reply

No trackbacks yet.

%d bloggers like this: