221 {
222 if (srcPixelTiles == null || !srcPixelTiles.Any())
223 return null;
224
225 srcPixelExtent = srcPixelExtent.ToIntegerExtent();
226 dstPixelExtent = dstPixelExtent.ToIntegerExtent();
227 int canvasWidth = (int)srcPixelExtent.Width;
228 int canvasHeight = (int)srcPixelExtent.Height;
229
230
231 Bitmap bf =
new Bitmap(canvasWidth, canvasHeight, PixelFormat.Format16bppGrayScale);
232 NetVips.Image canvas = NetVips.Image.NewFromMemory(bf.Bytes, bf.SizeX, bf.SizeX, 1, Enums.BandFormat.Ushort);
233
234 foreach (var tile in srcPixelTiles)
235 {
236 if (tile.Item2 == null)
237 continue;
238
239 fixed (byte* pTileData = tile.Item2)
240 {
241 var tileExtent = tile.Item1.ToIntegerExtent();
242 NetVips.Image tileImage = NetVips.Image.NewFromMemory((IntPtr)pTileData, (ulong)tile.Item2.Length, (int)tileExtent.Width, (int)tileExtent.Height, 1, Enums.BandFormat.Ushort);
243
244
245 var intersect = srcPixelExtent.Intersect(tileExtent);
246 if (intersect.Width == 0 || intersect.Height == 0)
247 continue;
248
249 int tileOffsetPixelX = (int)Math.Ceiling(intersect.MinX - tileExtent.MinX);
250 int tileOffsetPixelY = (int)Math.Ceiling(intersect.MinY - tileExtent.MinY);
251 int canvasOffsetPixelX = (int)Math.Ceiling(intersect.MinX - srcPixelExtent.MinX);
252 int canvasOffsetPixelY = (int)Math.Ceiling(intersect.MinY - srcPixelExtent.MinY);
253
254 using (var croppedTile = tileImage.Crop(tileOffsetPixelX, tileOffsetPixelY, (int)intersect.Width, (int)intersect.Height))
255 {
256
257 canvas = canvas.Composite2(croppedTile, Enums.BlendMode.Over, canvasOffsetPixelX, canvasOffsetPixelY);
258 }
259 }
260 }
261
262
263 if ((int)dstPixelExtent.Width != canvasWidth || (int)dstPixelExtent.Height != canvasHeight)
264 {
265 double scaleX = (double)dstPixelExtent.Width / canvasWidth;
266 double scaleY = (double)dstPixelExtent.Height / canvasHeight;
267 canvas = canvas.Resize(scaleX, vscale: scaleY, kernel: Enums.Kernel.
Nearest);
268 }
269
270 return canvas;
271 }
AForge.Bitmap Bitmap
Definition Bio.cs:21