locked
Canvas saving as image problem when scaling children elements over it with mouse

    Question

  • When I am scaling an image over my canvas with my mouse and try to save it as an image black using RenderBitmap code black color appears in my image as shown in the images First I am just changing canvas background with an image , then I am giving its height and width to canvas and then clipping its values.Canvas has image as children with manipulation delta event.

    var bm=new BitmapImage();
    bm.UriSource=new Uri(url,UriKind.RelativeOrAbsolute); 
    ImageBrush ib = new ImageBrush();
    ib.ImageSource = bm;
    DrawCanvas.Background = ib;
    DrawCanvas.Height = bm.PixelHeight;
    DrawCanvas.Width = bm.PixelWidth;
    DrawCanvas.Clip.Rect = new Rect(0, 0, bm.PixelWidth, bm.PixelHeight);

    Here ie my image scaling code

    private void MyImage_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
     {
      var transform = MyImage.RenderTransform as CompositeTransform;
     transform.ScaleX += e.Delta.Translation.X * 0.001;
     transform.ScaleY += e.Delta.Translation.Y * 0.001;
    }

    When I am not scaling canvas saving as image fine but when I am scaling this results appear .

    Need Help,Thanks

    Monday, June 16, 2014 1:29 AM

All replies

  • I'm not sure what you're asking.

    It may be that the Clip size must be off by a factor of the scale.

    DrawCanvas.Clip.Rect = new Rect(0, 0, bm.PixelWidth, bm.PixelHeight);


    Try PixelWidth times the scale transform.

    Monday, June 16, 2014 1:55 AM
  • Bryan I am just changing canvas background and assinging its width and height to canvas so that canvas should be of same dimension.Now I am clipping canvas so that children elements doesnot go outside.I have an image inside canvas which is scaling with mouse when I am not scaling it is saving correctly but when I am scaling as u can see in image , and then when try to save canvas it produce this , I dont know what is happening there,Please Help me.
    Monday, June 16, 2014 11:54 AM