Split an image into several pieces silverlight windows phone

北城余情 提交于 2019-12-22 12:36:21

问题


I want to split an image into several smaller images using silverlight for windows phone 7.5.

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.

Thank you for your help.


回答1:


WriteableBitmapEx is compatible with Windows Phone and has a Crop method to do exactly that. You just need to do the math to figure out how wide/tall and X/Y coordinates to crop at.

//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.




回答2:


You could combine your silverlight project with XNA and use 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. http://msdn.microsoft.com/en-us/library/hh202938(v=vs.92).aspx




回答3:


Combine ScaleTransform and TranslateTransform to render the correct section.

ScaleTransform (numXTiles,numYTiles)

Translate (xTileIndex / numXTiles, yTileIndex / numYTiles);

Place the ImageControl inside a Grid to do the clipping



来源:https://stackoverflow.com/questions/11108661/split-an-image-into-several-pieces-silverlight-windows-phone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!