Ecco, mi sembra di avere risolto. Ho creato un metodo che copia una bitmap in un'altra nella posizione (x0,y0). A me funziona alla grande. Se a qualcuno può servire ecco il codice:
codice:
public static void MarshallCopy(System.Drawing.Bitmap b1, int x0, int y0, System.Drawing.Bitmap b2)
{
//Imposta i dati di bmdata e blocca in memoria
System.Drawing.Rectangle rect1 = new System.Drawing.Rectangle(0, 0, b1.Width, b1.Height);
System.Drawing.Imaging.BitmapData bmdata1 = b1.LockBits(rect1, System.Drawing.Imaging.ImageLockMode.ReadWrite,
b1.PixelFormat);
System.Drawing.Rectangle rect2 = new System.Drawing.Rectangle(0, 0, b2.Width, b2.Height);
System.Drawing.Imaging.BitmapData bmdata2 = b2.LockBits(rect2, System.Drawing.Imaging.ImageLockMode.ReadWrite,
b2.PixelFormat);
//Array di rgbvalues
int bytes1 = Math.Abs(bmdata1.Stride) * b1.Height;
byte[] rgbvalues1 = new byte[bytes1];
int bytes2 = Math.Abs(bmdata2.Stride) * b2.Height;
byte[] rgbvalues2 = new byte[bytes2];
// Puntatori ad inizio
IntPtr pt1 = bmdata1.Scan0;
IntPtr pt2 = bmdata2.Scan0;
// Load dei pixel in array
System.Runtime.InteropServices.Marshal.Copy(pt1, rgbvalues1, 0, bytes1);
System.Runtime.InteropServices.Marshal.Copy(pt2, rgbvalues2, 0, bytes2);
int punt1, punt2;
int xmax = x0 + b2.Width;
int ymax = y0 + b2.Height;
if (xmax > b1.Width)
xmax = b1.Width;
if (ymax > b1.Height)
ymax = b1.Height;
//Copia dei valori rgb
for (int y = y0; y < ymax; y++)
for (int x = x0; x < xmax; x++)
{
punt1 = 4 * (x + b1.Width * y);
punt2 = 4 * ((x - x0) + b2.Width * (y - y0));
rgbvalues1[punt1] = rgbvalues2[punt2];
rgbvalues1[punt1 + 1] = rgbvalues2[punt2 + 1];
rgbvalues1[punt1 + 2] = rgbvalues2[punt2 + 2];
rgbvalues1[punt1 + 3] = rgbvalues2[punt2 + 3];
}
// Copia array su pixel
System.Runtime.InteropServices.Marshal.Copy(rgbvalues1, 0, pt1, bytes1);
// Chiusura
b1.UnlockBits(bmdata1);
}