Jpeg Image Import error - File Format Exception

2 posts, 0 answers
  1. Hema
    Hema avatar
    9 posts
    Member since:
    Feb 2015

    Posted 23 May 2016 Link to this post

    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))
                return formatProvider.Import(mmStream);


    Also attached the exception screen shot and sample Jpg file





  2. Todor
    Todor avatar
    168 posts

    Posted 25 May 2016 Link to this post

    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.

    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Back to Top