Windows Phone 8.1中裁剪图像的问题

本文关键字:图像 问题 裁剪 Phone Windows | 更新日期: 2023-09-27 18:27:25

我正在Windows Phone 8.1 Visual Studio 2013中制作一个应用程序(不是Windows Phone Store应用程序,只是Windows Phone应用程序),它可以从2张图像中进行全景处理。我几乎完成了我的申请。但最终,当我想裁剪结果时,我无法从画在图像上的矩形中发送正确的点。

private void btnCrop_Click(object sender, EventArgs e){
            // Get the size of the source image captured by the camera 
            double originalImageWidth = wbPanoramica.PixelWidth;
            double originalImageHeight = wbPanoramica.PixelHeight;
            // Get the size of the image when it is displayed on the phone 
            double displayedWidth = VisorPicture.ActualWidth;
            double displayedHeight = VisorPicture.ActualHeight;
            // Calculate the ratio of the original image to the displayed image 
            double widthRatio = originalImageWidth / displayedWidth;
            double heightRatio = originalImageHeight / displayedHeight;
            // Calculate the offset of the cropped image. This is the distance, in pixels, to the top left corner 
            // of the cropping rectangle, multiplied by the image size ratio. 
            int xoffset = (int)(((p1.X < p2.X) ? p1.X : p2.X) * widthRatio);
            int yoffset = (int)(((p1.Y < p2.Y) ? p1.Y : p2.X) * heightRatio);
            int X1 = (int)(p1.X * widthRatio);
            int Y1 = (int)(p1.Y * heightRatio);

            var cropped = wbPanoramica.Crop(X1, Y1, yoffset, xoffset);
            wbPanoramica = cropped;
            // Set the source of the image control to the new cropped bitmap
            VisorPicture.Source = wbPanoramica;
            rect.Visibility = Visibility.Collapsed;

            //Enable  accept and reject buttons to save or discard current cropped image.
            //Disable crop button until a new cropping region is selected.
            btnAceptar.IsEnabled = true;
            btnReject.IsEnabled = true;
            btnCortar.IsEnabled = false;
            //Instructional text
            textStatus.Text = "Continue editando la imagen, acepte, o rechace el cambio";
        }

Windows Phone 8.1中裁剪图像的问题

我找到你的问题了。这就像你在裁剪时没有得到确切的像素,对吧?我也有类似的问题。我做的是

wbPanoramica.Height=wbPanoramica.Height/2;
wbPanoramica.Width=wbPanoramica.Width/2;

在通过裁剪像素时,像这样通过

var cropped = wbPanoramica.Crop(X1*2, Y1*2, yoffset, xoffset);

让我知道这是否有助于