Welcome Guest! To enable all features, please Login or Register.

Notification

Icon
Error

Options
View
Last Go to last post Unread Go to first unread post
#1 Posted : Friday, February 15, 2013 11:50:22 AM(UTC)

EdS  
EdS

Groups: Registered
Posts: 11


The following program throws an "Invalid File Format" exception at codec.Load(path)

void Main(string[] args)
{
using (var codec = new RasterCodecs())
{
codec.Options.Load.Markers = true;
using (var image = codec.Load(path))
{
// do stuff with image...
}
}
}

The image can be any valid jp2 image. For example, a 24bpp bmp created in MSPaint and converted like so:

using (var c = new RasterCodecs())
using (var img = c.Load(@"C:\Untitled.bmp"))
{
c.Save(img, @"C:\converted.jp2", RasterImageFormat.Jp2, img.BitsPerPixel);
}

Why would this throw an exception? Can't it simply be ignored? I need to be able to load many types of images, some which may have different types of metadata. This behavior forces some awkward workarounds on the user of the API.
 

Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

#2 Posted : Sunday, February 17, 2013 7:43:18 AM(UTC)

Ibrahim  
Guest

Groups: Guests
Posts: 3,022

Was thanked: 2 time(s) in 2 post(s)

You can't set the codec.Options.Load.Markers to true if the image format that you want to load doesn't support Markers. Since the BMP doesn't support Markers, you can't set it to true. If you remove this line, you should be able to load it without any problem.

You can check if the format supports markers before loading the image. One way to do it is as follows:
===================
CodecsImageInfo INFO = codec.GetInformation(path,true);
if (INFO.Format == RasterImageFormat.Jpeg)
{
codec.Options.Load.Markers = true;
}
else
{
codec.Options.Load.Markers = false;
}
RasterImage image = codec.Load(path);
===================
 
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.

Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.094 seconds.