【问题标题】:Cropped Image is not aligned in center裁剪的图像未居中对齐
【发布时间】:2013-09-27 09:16:52
【问题描述】:

我正在 Windows phone 7 中开发照片应用程序。

当我按矩形区域裁剪图像时,裁剪后的图像与图像控件的左上角对齐。我想将图像居中对齐并将其缩放/拉伸到完整的图像控件。

看图。

第一张图片显示裁剪前,第二张图片显示裁剪后,图像左上角对齐。裁剪后的图像应居中对齐。并且请看到图2中裁剪的图像没有完全出现,我的意思是播放器的Boot部分也被裁剪了,但没有显示在裁剪的图像中,为什么会这样?

代码是:

    void ClipImage()
    {
        RectangleGeometry geo = new RectangleGeometry();

        r = (Rectangle)(from c in ImageLayout.Children where c.Opacity == .5 select    
      c).First();
        GeneralTransform gt = r.TransformToVisual(ImageLayout);
        Point p = gt.Transform(new Point(0, 0));
        geo.Rect = new Rect(p.X, p.Y, r.Width, r.Height);
        ImageMain.Clip = geo;
        r.Visibility = System.Windows.Visibility.Collapsed;

        TranslateTransform t = new TranslateTransform();
        t.X = -p.X;
        t.Y = -p.Y;
        ImageMain.RenderTransform = t;
    }

在代码中,我认为应该更改一些值,以使图像居中对齐。这只是一个裁剪的图像代码,里面还用到了很多其他的功能,但我认为并不关心。

【问题讨论】:

    标签: windows-phone-7 crop


    【解决方案1】:

    如果要使某些 XAML 元素居中,请使用 HorizontaAlignment.CenterVerticalAlignment.Center

    【讨论】:

    • 不,这不是通过 Xaml 对齐的,这是通过硬代码完成的,那么如何?
    猜你喜欢
    • 2011-10-05
    • 2012-01-30
    • 1970-01-01
    • 2019-06-11
    • 2019-10-23
    • 2021-07-05
    • 2013-12-24
    • 2013-01-06
    • 1970-01-01
    相关资源
    最近更新 更多