unsafe public void UpdateBitmap(SegmentRoot root) { if (root != null) { this.root = root; } if (!Closed) { return; } if (root == null || root.bmp == null) { return; } if (bmp != null) { bmp.Dispose(); } var expBound = GetExpandedBound(path); var pathBmp = DrawPath(expBound); Rectangle pixelBound = new Rectangle(); bool[] pixels = GetPixelsInPath(pathBmp, out pixelBound); offset = new Point(expBound.X + pixelBound.X, expBound.Y + pixelBound.Y); bmp = new Bitmap((int)pixelBound.Width, (int)pixelBound.Height, root.bmp.PixelFormat); using (var initer = new BitmapIterator(root.bmp, ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb)) using (var outiter = new BitmapIterator(bmp, ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb)) { for (int y = 0; y < pixelBound.Height; y++) { for (int x = 0; x < pixelBound.Width; x++) { if (pixels[pixelBound.Width * y + x]) { int xx = offset.X + x; int yy = offset.Y + y; if (xx < 0 || root.bmp.Width <= xx || yy < 0 || root.bmp.Height <= yy) { continue; } if (x < 0 || bmp.Width <= x || y < 0 || bmp.Height <= y) { continue; } int ii = initer.Stride * yy + 4 * xx; int oi = outiter.Stride * y + 4 * x; outiter.Data[oi + 0] = initer.Data[ii + 0]; outiter.Data[oi + 1] = initer.Data[ii + 1]; outiter.Data[oi + 2] = initer.Data[ii + 2]; outiter.Data[oi + 3] = initer.Data[ii + 3]; } } } } }
public Segment(string key, SegmentRoot root) { this.name = key; this.root = root; }