private void Vector2Bitmap(ShapePolygon shapePolygon) { //矢量转成位图 Dictionary <ShapePolygon, Color> vectors = new Dictionary <ShapePolygon, Color>(); vectors.Add(shapePolygon, Color.Red); IVector2BitmapConverter c = new Vector2BitmapConverter(); int width = (int)(shapePolygon.Envelope.Width / 0.1f); int height = (int)(shapePolygon.Envelope.Height / 0.1f); Size size = new System.Drawing.Size(width, height); Bitmap buffer = new Bitmap(size.Width, size.Height, PixelFormat.Format24bppRgb); c.ToBitmap(vectors, Color.White, shapePolygon.Envelope, size, ref buffer); buffer.Save("f:\\1.bmp", ImageFormat.Bmp); //位图转成栅格索引 Bitmap2RasterConverter b2r = new Bitmap2RasterConverter(); int[] idxs = b2r.ToRaster(buffer, Color.Red); //栅格索引转成位图 BinaryBitmapBuilder b = new BinaryBitmapBuilder(); buffer = b.CreateBinaryBitmap(size, Color.Red, Color.White); b.Fill(idxs, size, ref buffer); buffer.Save("f:\\2.bmp", ImageFormat.Bmp); }
private static int[] GetAOIByFeature(Bitmap bitmap, Color color) { using (IBitmap2RasterConverter c = new Bitmap2RasterConverter()) { return(c.ToRaster(bitmap, color)); } }