This is a migrated thread and some comments may be shown as answers.

Jpeg Image Import error - File Format Exception

1 Answer 74 Views
ImageEditor
This is a migrated thread and some comments may be shown as answers.
Hema
Top achievements
Rank 1
Hema asked on 24 May 2016, 03:07 AM

Hi team,

i am usng radImage Editor and trying to load jpg image in via ImageFormatProviderManager.import function and getting error that {"The image cannot be decoded. The image header might be corrupted."}.

 

Same image i can load in image editor demo wpf application given by telerik.

 

I want to know the reason

 

code here 

 string extension = Path.GetExtension(resource).ToLower();

            IImageFormatProvider formatProvider = ImageFormatProviderManager.GetFormatProviderByExtension(extension);
            //Image image = Image.FromFile(resource);
            MemoryStream mmStream = new MemoryStream();

            using (FileStream fsStream = File.OpenRead(resource))
            {
                fsStream.CopyTo(mmStream);
            }
            return formatProvider.Import(mmStream);

 

Also attached the exception screen shot and sample Jpg file

 

Regards

Hema

 

1 Answer, 1 is accepted

Sort by
0
Todor
Telerik team
answered on 26 May 2016, 08:19 AM
Hello Hema,

Thank you for the attachments.

The exception is thrown because the MemoryStream you are passing to the corresponding format provider's Import() method is not sought to the beginning and thus the position is not in the beginning. This means, you should invoke the following line of code (just to seek the stream) before passing the memory stream to the Import() method:

...
mmStream.Seek(0, SeekOrigin.Begin);
return formatProvider.Import(mmStream);

I hope this helps.

Regards,
Todor
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
ImageEditor
Asked by
Hema
Top achievements
Rank 1
Answers by
Todor
Telerik team
Share this question
or