This project is read-only.

Canvas.ToImage() error

Nov 13, 2009 at 10:09 PM



I was just creating a simple application saving a canvas to png, but I got this error on the first line:

ImageTools.Image = canvas.ToImage();

{System.ArgumentException: Bitmap cannot accessed ---> System.Security.SecurityException: "WriteableBitmap has protected content. Pixel access is not allowed."
   at System.Windows.Media.Imaging.WriteableBitmap.get_Pixels()
   at ImageTools.ImageExtensions.ToImage(WriteableBitmap bitmap)
   --- End of inner exception stack trace ---
   at ImageTools.ImageExtensions.ToImage(WriteableBitmap bitmap)
   at ImageTools.ImageExtensions.ToImage(Canvas canvas)
   at Center4.Floorplanner.Silverlight.Printer.PrintCanvas(Canvas canvas)
   at Center4.Floorplanner.Silverlight.MenuExpander.btPrint_Click(Object sender, RoutedEventArgs e)
   at System.Windows.Controls.Primitives.ButtonBase.OnClick()
   at System.Windows.Controls.Button.OnClick()
   at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
   at System.Windows.Controls.Control.OnMouseLeftButtonUp(Control ctrl, EventArgs e)
   at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName)}

Seems to be some kind of security exception, I don't know what I'm doing wrong here. Anyone else got this error?



Dec 24, 2009 at 10:59 AM

Hello Ed,

your canvas probably contains some cross-domain media... Read this

Hope it helps.