I want to use Magick.NET because I want the compression type to be JPEG and the System.Drawing.Imaging doesn't have that type.
The problem when it executes the line
Code: Select all
images.Write(outFile);
But the line is inside a using block and I never dispose that.System.ObjectDisposedException: Cannot access a disposed object.
My code:
Code: Select all
public void JoinTiffJPEG(string[] imageFiles, string outFile)
{
using (MagickImageCollection images = new MagickImageCollection())
{
try
{
MagickReadSettings settings = new MagickReadSettings();
settings.Compression = CompressionMethod.JPEG;
for (int i = 0; i <= (imageFiles.Length - 1); i++)
{
bool isError = false;
try
{
using (var image = new MagickImage(File.ReadAllBytes(imageFiles[i]), settings))
{
image.Settings.Compression = CompressionMethod.JPEG;
// Add the image
images.Add(image);
}
}
catch (Exception ex)
{
if (ex is System.IO.IOException)
MessageBox.Show("O ficheiro '" + imageFiles[i] + "' já existe na pasta escolhida.");
else
MessageBox.Show(ex.ToString(), "Erro", MessageBoxButtons.OK);
isError = true;
}
if (isError) continue;
}
images.Write(outFile);
//images.Dispose();
return;
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString(), "Erro", MessageBoxButtons.OK);
}
}
}