The following code attempts to save an image as a JPEG to a stream, but executing that line causes an app termination (and no exception catch). The BMP attempt above that works fine. Will I need to do anything else with this image before attempting to write it into a stream?
Saving images to files works fine so I'll use that as a workaround, but since my target is a database, I hope to get saving and loading from streams to increase performance.
private void iem_AfterAcquireBitmap(object sender, HiComponents.IEvolution.IEAfterAcquireBitmapEventArgs e)
{
IEImage img = iem.ImageList.GetImage(e.Index);
img.Crop(0, 0, (int)(8.5 * 300) - 1, (int)(11 * 300) - 1);
img.SaveImage($"{path}\\img{e.Index}.jpg");
MemoryStream ms;
// save as BMP -- works fine
ms = new MemoryStream();
try
{
img.SaveImage(ms, IEFileFormats.BMP);
File.WriteAllBytes($"{path}\\img{e.Index}a.bmp", ms.ToArray());
}
catch (Exception ex)
{
}
// save as JPG -- causes app termination on SaveImage line
ms = new MemoryStream();
try
{
img.SaveImage(ms, IEFileFormats.JPEG);
File.WriteAllBytes($"{path}\\img{e.Index}a.jpg", ms.ToArray());
}
catch (Exception ex) // never hit
{
}
var ii = iem.ImageList.GetImageInfo(e.Index);
}
Thanks.
-C