将图像分成几块silverlight窗口手机

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

首先,我想知道这是否可能(我最近对Windows Phone API有一些令人不快的意外),如果是,请给我一些例子,因为我能够找到完全没有。

谢谢您的帮助。

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。

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

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

结合ScaleTransform和TranslateTransform以呈现正确的部分。

ScaleTransform(numXTiles,numYTiles)

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

将ImageControl放在网格中以进行裁剪