public void CreatePictrue(WriteableBitmap source) { pictrueshow.Source = source; pictrueshow.UpdateLayout(); int i = 0; for (int w = 0; w < GameGlobal.MaxTilesW; w++) { for (int h = 0; h < GameGlobal.MaxTilesH; h++) { var tile = Tiles.Children[i] as Tile; WriteableBitmap temp = source.Resize((int)Tiles.Width, (int)Tiles.Height, WriteableBitmapExtensions.Interpolation.Bilinear); var rect = new Rect(w * GameGlobal.TileW, h * GameGlobal.TileH, (int)GameGlobal.TileW, (int)GameGlobal.TileH); temp = temp.Crop(rect); temp.Invalidate(); tile.IndexX = tile.CorrectIndexX = w; tile.IndexY = tile.CorrectIndexY = h; tile.ImageSource = temp; i += 1; } } foreach (Tile item in Tiles.Children) { var r = GameGlobal.Random.Next(Tiles.Children.Count); var temp = Tiles.Children[r] as Tile; var x = temp.IndexX; var y = temp.IndexY; temp.IndexX = item.IndexX; temp.IndexY = item.IndexY; item.IndexX = x; item.IndexY = y; } ANI_Starting.Begin(); }
public void CreatePictrue(BitmapImage source) { if (source == null) { MessageBox.Show("资源错误"); } pictrueshow.Source = source; pictrueshow.UpdateLayout(); int i = 0; for (int w = 0; w < GameGlobal.MaxTilesW; w++) { for (int h = 0; h < GameGlobal.MaxTilesH; h++) { var tile = Tiles.Children[i] as Tile; WriteableBitmap temp = new WriteableBitmap((int)GameGlobal.TileW, (int)GameGlobal.TileH); tile.ImageSource = temp; temp.Render(pictrueshow, new TranslateTransform() { X = -w * GameGlobal.TileW, Y = -h * GameGlobal.TileH }); temp.Invalidate(); tile.IndexX = tile.CorrectIndexX = w; tile.IndexY = tile.CorrectIndexY = h; tile.ImageSource = temp; i += 1; } } foreach (Tile item in Tiles.Children) { var r = GameGlobal.Random.Next(Tiles.Children.Count); var temp = Tiles.Children[r] as Tile; var x = temp.IndexX; var y = temp.IndexY; temp.IndexX = item.IndexX; temp.IndexY = item.IndexY; item.IndexX = x; item.IndexY = y; } ANI_Starting.Begin(); }