void CopyTo(BitmapHandler bmp, Rectangle source) { var bd = bmp.Lock(); if (source.Top < 0 || source.Left < 0 || source.Right > size.Width || source.Bottom > size.Height) { throw new Exception("Source rectangle exceeds image size"); } // we have to draw to a temporary bitmap pixel by pixel unsafe { /*fixed (byte* pSrc = Control)*/ { var dest = (byte *)bd.Data; //var src = pSrc; var src = (byte *)ptr; var scany = size.Width; /*if (false) * { * src += Control.Length - scany; * scany = -scany; * }*/ dest += source.Top * bd.ScanWidth; dest += source.Left * sizeof(uint); src += source.Top * scany; src += source.Left; int bottom = source.Bottom; int right = source.Right; int left = source.Left; for (int y = source.Top; y < bottom; y++) { var srcrow = src; var destrow = (uint *)dest; for (int x = left; x < right; x++) { * destrow = colors [*srcrow]; destrow++; srcrow++; } dest += bd.ScanWidth; src += scany; } } } bmp.Unlock(bd); }
void CopyTo(BitmapHandler bmp, Rectangle source) { if (source.Top < 0 || source.Left < 0 || source.Right > size.Width || source.Bottom > size.Height) { throw new Exception("Source rectangle exceeds image size"); } // we have to draw to a temporary bitmap pixel by pixel var bd = bmp.Lock(); unsafe { var dest = (byte *)bd.Data; var src = (byte *)ptr; var scany = size.Width; dest += source.Top * bd.ScanWidth; dest += source.Left * bd.BytesPerPixel; src += source.Top * scany; src += source.Left; int bottom = source.Bottom; int right = source.Right; int left = source.Left; scany = scany - (right - left); for (int y = source.Top; y < bottom; y++) { var destrow = (uint *)dest; for (int x = left; x < right; x++) { *destrow = colors[*src]; destrow++; src++; } dest += bd.ScanWidth; src += scany; } } bmp.Unlock(bd); }