我想使用windows phone 7.5版的silverlight将一个图像分割成几个较小的图像。
首先,我想知道这是否可能(我最近在windows phone APIs上遇到了一些令人不快的惊喜),如果是的话,请给我一些例子,因为我完全找不到。
谢谢你的帮助。
发布于 2012-06-20 04:34:35
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。
发布于 2012-06-20 04:18:09
您可以将您的silverlight项目与XNA结合使用,并使用spritebatch.Draw()。它有一个源矩形的参数,可以让你从图像中绘制一个零件。
MSDN对如何结合silverlight和XNA有一些帮助。http://msdn.microsoft.com/en-us/library/hh202938(v=vs.92).aspx
发布于 2012-06-20 04:27:11
组合ScaleTransform和TranslateTransform以呈现正确的部分。
ScaleTransform (numXTiles,numYTiles)
翻译(xTileIndex / numXTiles,yTileIndex / numYTiles);
将ImageControl放在网格内以进行裁剪
https://stackoverflow.com/questions/11108661
复制相似问题