Reputation: 88
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.
Upvotes: 2
Views: 3136
Reputation: 23218
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.
Upvotes: 4
Reputation: 902
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
Upvotes: 0
Reputation: 133
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
Upvotes: 0