1

I have written an application in silverlight, I am placing a rectangle on the image and want to select the part of image covered by rectangle and show it on a image control on click of a button.

I am not good at handling ratios and image manipulation things, so I am unable to get it right way.

The code for the same goes as below, and would appreciate, if anyone could suggest me a way or solution to get around with this.

public void CaptureImage(object sender, RoutedEventArgs e)
{
            BitmapImage bitmapImage = new BitmapImage();
            //// bitmapImage.CreateOptions = BitmapCreateOptions.None;
            bitmapImage = NewImage;

            ////calculate bounding box
            int originalWidth = bitmapImage.PixelWidth;
            int originalHeight = bitmapImage.PixelHeight;

            int newSmallWidth = (int)SquareBlue.Width;
            int newSmallHeight = (int)SquareBlue.Height;

            ////generate temporary control to render image
            Image temporaryImage = new Image { Source = bitmapImage, Width = newSmallWidth, Height = newSmallHeight };

            ////create writeablebitmap
            WriteableBitmap wb = new WriteableBitmap(newSmallWidth, newSmallHeight);

            TranslateTransform t = new TranslateTransform();
            t.X = -5;
            t.Y = -5;

            wb.Render(temporaryImage, t);

            wb.Invalidate();

            myImage.Source = wb;
   }

Whenever this code gets executed, whole image gets snapped, instead of the part selected by rectangle. Could anyone, guide me as what I am doing wrong here.

DotNetGeek
  • 165
  • 11

1 Answers1

0

I'd recommend that you use the Crop method the WriteableBitmapEx library provides.

Rene Schulte
  • 2,962
  • 1
  • 19
  • 26
  • 1
    I would recommend using a pen and paper to think about the problem you have and use some sample values. Think about your problem. – Rene Schulte Oct 14 '13 at 15:05