0

我使用佳能 EDSDK Api 的 Net 4.0 Wpf 照相亭应用程序由于不断出现内存不足错误(例如:

System.OutOfMemoryException:内存不足。在 System.Drawing.Image.FromStream(流流,布尔值 useEmbeddedColorManagement,布尔值 validateImageData)

当应用程序捕获图像并将其从相机下载到计算机然后尝试将图像裁剪到特定尺寸时,这种情况经常发生

以下是最常发生崩溃的片段:

private void MainCamera_DownloadReady(EOSDigital.API.Camera sender, EOSDigital.API.DownloadInfo Info)
    {
        try
        {
            Info.FileName = "CamPic.jpg";
            string dir = AppDomain.CurrentDomain.BaseDirectory;
            sender.DownloadFile(Info, dir); //Download image from camera to PC

            //Crop image to specific dimensions
            Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
            {
                PhotoObject ph;

                using (ImageFactory imf = new ImageFactory())
                {
                    imf.Load(AppDomain.CurrentDomain.BaseDirectory + @"\CamPic.jpg");
                    if (((WebcamImageVM)DataContext).IsPortrait)
                    {
                        imf.Crop(new System.Drawing.Rectangle(600, 0, 720, 1080));
                        ph = new PhotoObject(WebcamImageVM.GetBitmapSource(new Bitmap(imf.Image)), true);
                    }
                    else
                    {
                        imf.Crop(new System.Drawing.Rectangle(150, 0, 1620, 1080));
                        ph = new PhotoObject(WebcamImageVM.GetBitmapSource(new Bitmap(imf.Image)), false);
                    }
                }
            }));
        }
        catch (Exception ex)
        {
            Logger.LogEvent(EventType.Error, "Failed to take photo with DSLR: " + ex.Message);
        }
    }

任何建议将不胜感激

4

0 回答 0