Windows Phone 8.1 中的裁剪图像问题

Posted

技术标签:

【中文标题】Windows Phone 8.1 中的裁剪图像问题【英文标题】:problems with crop image in Windows Phone 8.1 【发布时间】:2014-10-21 23:57:58 【问题描述】:

我正在 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";
        

【问题讨论】:

【参考方案1】:

我有你的问题。就好像你在裁剪时没有得到准确的像素,对吗? 我也有类似的问题。我所做的是

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

在传递裁剪像素时,像这样传递它

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

如果有帮助请告诉我

【讨论】:

以上是关于Windows Phone 8.1 中的裁剪图像问题的主要内容,如果未能解决你的问题,请参考以下文章

Windows phone 8.1 裁剪矩形

Windows Phone 8.1 RT 中的 ViewportControl 是啥?

如何将 C# 中的 Image 对象制作到 Windows Phone 8.1

在 windows phone 8.1 中将 Base64String 图像显示为 MapIcon 图像

带有图像标签的 Binging 字符串 - Windows Phone 8.1 UWP

具有多个页面的 Windows Phone 8.1 自定义控件