OutOfMemoryException in image editor

1 Answer 65 Views
ImageEditor
Chao
Top achievements
Rank 1
Chao asked on 27 Jul 2022, 03:22 PM

Hi,

when i recently use the image editor with big picture(for example 6000*5000 pixel), after drawing several rectangle using shape tool, it gave me:

System.OutOfMemoryException: Insufficient memory to continue the execution of the program.
   at System.Windows.Media.Imaging.WriteableBitmap.InitFromBitmapSource(BitmapSource source)
   at System.Windows.Media.Imaging.WriteableBitmap..ctor(BitmapSource source)
   at Telerik.Windows.Media.Imaging.RadBitmap..ctor(Int32 width, Int32 height, FrameworkElement element, Boolean measureAndArrange)
   at Telerik.Windows.Media.Imaging.Commands.DrawCommand.Execute(RadBitmap source, Object context)
   at Telerik.Windows.Media.Imaging.History.ImageHistory.Execute(IImageCommand command, Object context)
   at Telerik.Windows.Controls.RadImageEditor.ExecuteCommand(IImageCommand command, Object context)
   at Telerik.Windows.Controls.RadImageEditor.CommitTool(Boolean executeSameToolAfterCommit)
   at Telerik.Windows.Media.Imaging.Tools.DrawToolBase.InvokeEndDraw(Point point)
   at Telerik.Windows.Media.Imaging.Tools.DrawToolBase.DrawingCanvas_MouseLeftButtonUp(Object sender, MouseButtonEventArgs e)
   at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
   at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)
   at System.Windows.UIElement.OnMouseUpThunk(Object sender, MouseButtonEventArgs e)
   at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
   at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
   at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
   at System.Windows.Input.InputManager.ProcessStagingArea()
   at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
   at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
   at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
   at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)

 

it seems that related to the history memory to me, based on previous discussion:

https://www.telerik.com/forums/out-of-memory-exception-when-cropping-image

but when i assgin a larger MaximumMemoryBufferSize in the imageeditor, the issue still remained, any suggestions on this?

1 Answer, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 28 Jul 2022, 11:50 AM

Hello Chao,

This error is a combination between a memory issue in the WriteableBitmap class we use and the history feature of the control. I am afraid that there isn't a very good workaround that I can suggest, but here are couple of ideas.

  • Try setting the MaximumMemoryBufferSize to a smaller value. I've seen that in the other thread (the support ticket), this was set to 4294967295 which are around 4GB. With this memory allowance, even if you don't hit the WriteableBitmap issue, you will reach the memory limit of the .NET framework which is around 4GB.
  • Check the current memory used by the application and call the Clear() method of the History object.

Additional to this, we have a feature request to introduce a smarter way to contain the history. Currently, when you make a change a copy of the entire picture is hold into memory. This happens for each change, which builds up memory pretty fast. The feature will allow to store information only about the changed pixels, which will have great impact on the memory decrease.

Regards,
Martin Ivanov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
ImageEditor
Asked by
Chao
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or