简体   繁体   English

将图像分成几块Silverlight Windows Phone

[英]Split an image into several pieces silverlight windows phone

I want to split an image into several smaller images using silverlight for windows phone 7.5. 我想使用适用于Windows Phone 7.5的silverlight将图像分成几个较小的图像。

First of all, i want to know if this is even possible (i had some unpleasant surprises with windows phone APIs lately), and if it is, just give me some example as i have been able to find exactly none. 首先,我想知道这是否有可能(最近我对Windows Phone API感到不愉快),如果可以,请给我一些示例,因为我完全找不到。

Thank you for your help. 谢谢您的帮助。

WriteableBitmapEx is compatible with Windows Phone and has a Crop method to do exactly that. WriteableBitmapEx与Windows Phone兼容,并且具有Crop方法可以精确地做到这一点。 You just need to do the math to figure out how wide/tall and X/Y coordinates to crop at. 您只需要进行数学运算即可确定要裁剪的宽/高和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);

I might be off by a pixel (didn't test) in my above example, but it should demonstrate the API. 在上面的示例中,我可能有一个像素(没有测试),但是它应该演示API。

You could combine your silverlight project with XNA and use spritebatch.Draw(). 您可以将Silverlight项目与XNA结合使用,并使用spritebatch.Draw()。 It has a parameter for source rectangle, which lets you draw a part from the image. 它具有用于源矩形的参数,可用于从图像中绘制零件。

MSDN has some help for how to combining silverlight and XNA. MSDN对于如何将Silverlight和XNA结合在一起提供了一些帮助。 http://msdn.microsoft.com/en-us/library/hh202938(v=vs.92).aspx http://msdn.microsoft.com/en-us/library/hh202938(v=vs.92).aspx

Combine ScaleTransform and TranslateTransform to render the correct section. 结合ScaleTransform和TranslateTransform渲染正确的部分。

ScaleTransform (numXTiles,numYTiles) ScaleTransform(numXTiles,numYTiles)

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

Place the ImageControl inside a Grid to do the clipping 将ImageControl放置在网格内进行裁剪

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM