public void SetLayer(LayerItem layerItem) { bool bInitialize = (null == bufferImage); if (bInitialize) { bufferImage = new Bitmap( ColumnCount * BlockWidth, RowCount * BlockHeight, System.Drawing.Imaging.PixelFormat.Format32bppArgb); idMap.Clear(); } using (var g = Graphics.FromImage(bufferImage)) { if (bInitialize) { g.Clear(Color.Transparent); } for (int rowIndex = 0; rowIndex < layerItem.Data.IDMap.Count; rowIndex++) { List<int> row = layerItem.Data.IDMap[rowIndex]; for (int columnIndex = 0; columnIndex < row.Count; columnIndex++) { int id = row[columnIndex]; if (idMap.Count <= rowIndex) { idMap.Add(Enumerable.Repeat(-1, ColumnCount).ToList()); } idMap[rowIndex][columnIndex] = id; } } if (null != layerItem.Image) { g.DrawImage(layerItem.Image, Point.Empty); } } }
public void MakeLayerImage(LayerItem layerItem, List<Image> partsImages) { int canvasWidth = BlockWidth * ((0 == layerItem.Data.IDMap.Count) ? 1 : layerItem.Data.IDMap[0].Count); int canvasHeight = BlockHeight * ((0 == layerItem.Data.IDMap.Count) ? 1 : layerItem.Data.IDMap.Count); if (null == layerItem.Image || layerItem.Image.Width != canvasWidth || layerItem.Image.Height != canvasHeight) { if (null != layerItem.Image) { layerItem.Image.Dispose(); layerItem.Image = null; } layerItem.Image = new Bitmap(canvasWidth, canvasHeight, System.Drawing.Imaging.PixelFormat.Format32bppArgb); } using (var g = Graphics.FromImage(layerItem.Image)) { g.Clear(Color.Transparent); for (int rowIndex = 0; rowIndex < layerItem.Data.IDMap.Count; rowIndex++) { var row = layerItem.Data.IDMap[rowIndex]; for (int columnIndex = 0; columnIndex < row.Count; columnIndex++) { int id = row[columnIndex]; if (id < 0 || partsImages.Count <= id) continue; g.DrawImage(partsImages[id], columnIndex * BlockWidth + BorderWidth, rowIndex * BlockHeight + BorderWidth); } } } }