【问题标题】:Split an image into several pieces silverlight windows phone将图像拆分为几块 silverlight windows phone
【发布时间】:2012-06-21 22:42:59
【问题描述】:

我想使用 Silverlight for windows phone 7.5 将图像拆分为几个较小的图像。

首先,我想知道这是否可能(我最近对 ​​windows phone API 有一些令人不快的惊喜),如果是,请给我一些例子,因为我完全找不到。

感谢您的帮助。

【问题讨论】:

    标签: c# silverlight image windows-phone-7 split


    【解决方案1】:

    WriteableBitmapEx 与 Windows Phone 兼容,并且有一个 Crop 方法可以做到这一点。您只需进行数学计算即可确定要裁剪的宽度/高度和 X/Y 坐标。

    //this creates the four quadrants of sourceBitmap as new bitmaps
    
    int halfWidth = sourceBitmap.PixelWidth / 2;
    int halfHeight = sourceBitmap.PixelHeight / 2;
    
    WriteableBitmap topLeft = sourceBitmap.Crop(0, 0, halfWidth, halfHeight);
    WriteableBitmap topRight = sourceBitmap.Crop(halfWidth, 0, halfWidth, halfHeight);
    WriteableBitmap bottomLeft = sourceBitmap.Crop(0, halfHeight, halfWidth, halfHeight);
    WriteableBitmap bottomRight = sourceBitmap.Crop(halfWidth, halfHeight, halfWidth, halfHeight);
    

    在上面的示例中,我可能偏离了一个像素(未测试),但它应该演示 API。

    【讨论】:

      【解决方案2】:

      您可以将您的 silverlight 项目与 XNA 结合使用 spritebatch.Draw()。 它有一个源矩形的参数,可以让你从图像中绘制一个部分。

      MSDN 对如何结合 silverlight 和 XNA 有一些帮助。 http://msdn.microsoft.com/en-us/library/hh202938(v=vs.92).aspx

      【讨论】:

        【解决方案3】:

        结合 ScaleTransform 和 TranslateTransform 来渲染正确的部分。

        ScaleTransform (numXTiles,numYTiles)

        翻译(xTileIndex / numXTiles,yTileIndex / numYTiles);

        将 ImageControl 放置在 Grid 中以进行剪辑

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2013-11-05
          • 1970-01-01
          相关资源
          最近更新 更多