2012-06-19 24 views
2

我想使用Silverlight for Windows Phone 7.5將圖像分成幾個較小的圖像。首先,我想知道這是否甚至有可能(最近我有一些令人不快的意外),如果是這樣,就給我舉個例子吧,因爲我已經找不到任何東西了。將圖像分成幾塊silverlight windows手機

謝謝你的幫助。

回答

4

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。

0

合併ScaleTransform和TranslateTransform以呈現正確的部分。

ScaleTransform(numXTiles,numYTiles)

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

放置一個網格內的ImageControl做裁剪