2
I am using Magick.NET to choose JPEG compression for my TIFF files. So, I save each one with this compression in a collection of images. Finally I want to join all the TIFF of the collection in one file.
But when I do "images. Match();" I get the error:
I also tried to do the same action without the above mentioned line of code but I get the same error. However, I don’t see where the object was Disposed
because everything is inside a block using
.
Code:
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++)
{
using (var image = new MagickImage(File.ReadAllBytes(imageFiles[i]), settings))
{
image.Settings.Compression = CompressionMethod.JPEG;
// Add the image
images.Add(image);
}
}
images.Combine();
Stream output = new FileStream(outFile, FileMode.Create);
images.Write(output, MagickFormat.Tif);
//images.Dispose();
return;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "Erro", MessageBoxButtons.OK);
}
}
}
Throw away the
using
, on the lineusing (var image = ...)
.– Marcelo Shiniti Uchimura
@Marceloshinitiuchimura That’s it, thank you! However, the file only has the first page and not all... Can you help me with this or should I post a new question?
– Sofia Rodrigues
New question, if you please.
– Marcelo Shiniti Uchimura
Okay. Thank you.
– Sofia Rodrigues
@Marceloshinitiuchimura Please put this in the answer. And Sofia, when there is the answer, please mark as solved. : ) This can help others to have the same doubt.
– Ronaldo Araújo Alves
All right, I’ll do it.
– Sofia Rodrigues