private Bitmap GetBitmapUseRaster(PointF[] points, byte[] types, Envelope dstEnvelope, Size size) { if (dstEnvelope == null || size.IsEmpty) { return(null); } using (IVector2BitmapConverter c = new Vector2BitmapConverter()) { Bitmap buffer = new Bitmap(size.Width, size.Height, PixelFormat.Format24bppRgb); c.ToBitmapUseRasterCoord(points, types, Color.Red, Color.Black, dstEnvelope, size, ref buffer); return(buffer); } }
/// <summary> /// 函数GetBitmapUseRasterII解决大图像栅格化出现内存溢出的错误 /// 解决方法: /// 1、先按照AOI最小外包矩形栅格化; /// 2、将栅格化后的索引平移至大图像。 /// </summary> /// <param name="points"></param> /// <param name="types"></param> /// <param name="dstEnvelope"></param> /// <param name="size"></param> /// <param name="offsetX"></param> /// <param name="offsetY"></param> /// <param name="newSize"></param> /// <returns></returns> private Bitmap GetBitmapUseRasterII(PointF[] points, byte[] types, Envelope dstEnvelope, Size size, out int offsetX, out int offsetY, out Size newSize) { offsetX = offsetY = 0; newSize = Size.Empty; if (dstEnvelope == null || size.IsEmpty) { return(null); } // float minX = float.MaxValue; float maxX = int.MinValue; float minY = float.MaxValue; float maxY = float.MinValue; for (int i = 0; i < points.Length; i++) { if (points[i].X < minX) { minX = points[i].X; } if (points[i].X > maxX) { maxX = points[i].X; } if (points[i].Y < minY) { minY = points[i].Y; } if (points[i].Y > maxY) { maxY = points[i].Y; } } // offsetX = (int)minX; offsetY = (int)minY; int width = (int)(maxX - minX); int height = (int)(maxY - minY); if (width <= 0 || height <= 0) { return(null); } newSize = new Size(width, height); for (int i = 0; i < points.Length; i++) { points[i].X -= minX; points[i].Y -= minY; } // double xSpan = dstEnvelope.Width / size.Width; double ySpan = dstEnvelope.Height / size.Height; double minXCoord = dstEnvelope.MinX + offsetX * xSpan; double maxYCoord = dstEnvelope.MaxY - offsetY * ySpan; double maxXCoord = minXCoord + width * xSpan; double minYCoord = maxYCoord - height * ySpan; Envelope newEnvelope = new Envelope(minXCoord, minYCoord, maxXCoord, maxYCoord); //offsetY = Math.Abs(offsetY); // using (IVector2BitmapConverter c = new Vector2BitmapConverter()) { Bitmap buffer = new Bitmap(width, height, PixelFormat.Format24bppRgb); c.ToBitmapUseRasterCoord(points, types, Color.Red, Color.Black, newEnvelope, newSize, ref buffer); return(buffer); } }