I linguaggi .NET vengono trattati nel forum "Visual Basic e .NET Framework".
Sposto.
Ciao.![]()
I linguaggi .NET vengono trattati nel forum "Visual Basic e .NET Framework".
Sposto.
Ciao.![]()
"Perchè spendere anche solo 5 dollari per un S.O., quando posso averne uno gratis e spendere quei 5 dollari per 5 bottiglie di birra?" [Jon "maddog" Hall]
Fatti non foste a viver come bruti, ma per seguir virtute e canoscenza
Non so se ho capito. Supponendolo, creo una bitmap con le dimensioni delle due, dopo di che copio la prima per esempio, in posizione 0,0 e la seconda, per esempio, in posizione wPrimaImmagine, 0, se sono messe in orizzontale
Pietro
ecco
Ultima modifica di escocat; 11-02-2015 a 16:52
Sto scrivendo un metodo statico ma non mi copia le colonne per bene: dove sbaglio?
codice:public static void MarshallCopy(System.Drawing.Bitmap b1, int x0, int y0, System.Drawing.Bitmap b2) { //Copio il contenuto di b1 in bmdata1 System.Drawing.Rectangle rect = new System.Drawing.Rectangle(0, 0, b1.Width, b1.Height); System.Drawing.Imaging.BitmapData bmdata1 = b1.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, b1.PixelFormat); //Copio il contenuto di b2 in bmdata2 rect = new System.Drawing.Rectangle(0, 0, b2.Width, b2.Height); System.Drawing.Imaging.BitmapData bmdata2 = b2.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, b2.PixelFormat); //Array di rgbvalues in bmdata1 int bytes1 = Math.Abs(bmdata1.Stride) * b1.Height; byte[] rgbvalues1 = new byte[bytes1]; //Array di rgbvalues in bmdata2 int bytes2 = Math.Abs(bmdata2.Stride) * b2.Height; byte[] rgbvalues2 = new byte[bytes2]; // Puntatore in b1 ad inizio area IntPtr pt1 = bmdata1.Scan0; // Puntatore in b2 ad inizio bmdata1 IntPtr pt2 = bmdata2.Scan0; // Copia dei valori in bmdata1 System.Runtime.InteropServices.Marshal.Copy(pt1, rgbvalues1, 0, bytes1); // Copia dei valori in bmdata2 System.Runtime.InteropServices.Marshal.Copy(pt2, rgbvalues2, 0, bytes2); //puntatore in b1 di (x0,y0) è 4 * (x0 + b1.Width * y0) int punt2=0; //puntatori int non IntPtr for (int p = 0; p < b2.Width; p++) { pt1 = (System.IntPtr)(4 * (x0 + b1.Width * (y0+p))); for (int i = 0; i < b2.Width; i++) { rgbvalues1[(int)pt1 + i] = rgbvalues2[punt2 + i]; punt2++; } } // Copia dei valori rgb in b1 pt1 = bmdata1.Scan0; System.Runtime.InteropServices.Marshal.Copy(rgbvalues1, 0, pt1, bytes1); // Chiusura b1. b1.UnlockBits(bmdata1); }
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); }