LEADTOOLS Support
General
General Questions
Getting "Invalid File Format" in Codec.Load()
This topic and its replies were posted before the current version of LEADTOOLS was released and may no longer be applicable.
#1
Posted
:
Thursday, April 2, 2009 9:50:06 PM(UTC)
Groups: Registered
Posts: 6
Hi,
When I use codecs.load() i am getting "Invalid File Format" error message.
I am using LeadTools version 16. Reference have been given to the following dlls.
Leadtools.dll,Leadtools.winforms.dll,Leadtools.codecs.dll,Leadtools.codecs.jpg.dll. And the same dlls have been copied the directory where my exe resides.
Please find below the code.
RasterCodecs.Startup();
RasterCodecs codecs = new RasterCodecs();
Tried the following methods
1 . RasterImage tempImg = codecs.Load(@"C:\\Program Files\\Readiris Pro 8\\autoform.jpg", 8, Leadtools.Codecs.CodecsLoadByteOrder.BgrOrGray, 1, -1);
2. RasterImage tempImg = codecs.Load(@"C:\\Program Files\\Readiris Pro 8\\autoform.jpg");
3. System.Drawing.Image image = System.Drawing.Image.FromFile(@"C:\\Program Files\\Readiris Pro 8\\autoform.jpg");
MemoryStream stream = new MemoryStream();
image.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
RasterImage tempImg = codecs.Load(stream);
RasterCodecs.Shutdown();
I am getting the same error in all the above three methods.
Please help me in fixing this issue.
#2
Posted
:
Sunday, April 5, 2009 2:38:36 AM(UTC)
Groups: Guests
Posts: 3,022
Was thanked: 2 time(s) in 2 post(s)
I'm afraid you are not including the correct reference for loading a JPEG image. We don't have a DLL named leadtools.codecs.jpg.dll. Either you misspelled it or you are using a non-LEAD DLL.
To load a JPEG image you need to add leadtools.codecs.CMP.DLL to your project references.
#3
Posted
:
Sunday, April 5, 2009 9:05:38 PM(UTC)
Groups: Registered
Posts: 6
Thanks for your response. I have solved this issue by giving the following statement before loading the loading the image into codecs.
codecs.Options.Load.Format =
RasterImageFormat.Jpeg;
RasterImage tempImg = codecs.Load(@"C:\\Program Files\\Readiris Pro 8\\alphabets.Jpg");
what should be format type for the following code
System.Drawing.
Image image = System.Drawing.Image.FromFile(@"C:\\Program Files\\Readiris Pro 8\\alphabets.tif");
MemoryStream stream = new MemoryStream();
image.Save(stream, System.Drawing.Imaging.
ImageFormat.Tiff);
RasterCodecs.Startup();
RasterCodecs codecs = new RasterCodecs();
RasterImage
tempImg = codecs.Load(stream);
I tried with Jpeg and Tif and several other options. It's giving "Invalid File Format" in Codecs.load(stream) statement.
Please help me in fixing the same.
#4
Posted
:
Monday, April 6, 2009 2:29:06 AM(UTC)
Groups: Guests
Posts: 3,022
Was thanked: 2 time(s) in 2 post(s)
You do NOT need to set codecs.Options.Load.Format before loading. You only need to include the correct DLLs
About the new issue, it is most likely caused by the stream pointer not being positioned at the stream start. Please try to seek to the stream beginning before calling our Load() function like this:
stream.Seek(0, SeekOrigin.Begin)
#5
Posted
:
Monday, April 6, 2009 3:01:19 AM(UTC)
Groups: Registered
Posts: 6
It worked.Thank you so much.
#6
Posted
:
Thursday, November 19, 2009 1:39:48 PM(UTC)
Groups: Registered
Posts: 2
Basel,
I followed your instructions and added a reference to Leadtools.Codecs.Cmp.dll in my C# project and I still get the "Invalid File Format" message when attempting to load a jpg file.
Here's my code:
RasterCodecs.Startup();
RasterCodecs codecs = new RasterCodecs();
codecs.ThrowExceptionsOnInvalidImages = true;
try
{
codecs.Options.Load.Format = RasterImageFormat.Jpeg;
RasterImage image = codecs.Load(@"D:\Development\Applications\2010ReservesImaging\2010ReservesImaging\2010ReservesImaging\bin\Debug\Images\" + "60a15f91-bcb5-44f3-90db-29dd3f9be771.jpg");
}
What do I need to do different to get this error to resolve?
Your help is much appreciated!!
Steven
#7
Posted
:
Saturday, November 21, 2009 11:37:21 PM(UTC)
Groups: Registered, Tech Support
Posts: 1,326
Was thanked: 1 time(s) in 1 post(s)
Steven,
Can you please send me the JPEG image that you are trying to load?
Please put the JPEG image in a ZIP or RAR file and either post it here or send it to
support@leadtools.com and mention this forum post.
Thanks,
Maen Badwan
LEADTOOLS Technical Support
#8
Posted
:
Sunday, January 31, 2010 1:34:58 PM(UTC)
Groups: Registered
Posts: 2
Maen,
Sorry it has taken me so long to respond. I didn't know you had responded to my post. Should I expect notification by e-mail when a post I've made has been answered or responded to?
Either way, I don't have that problem anymore as we've switched from using .jpg/.jpeg files to using .png files. I then added a reference to Leadtools.Codecs.Png in my .net project and everything works fine.
Thanks for your reply,
Steven
LEADTOOLS Support
General
General Questions
Getting "Invalid File Format" in Codec.Load()
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.