Probabilmente stai allocando nuove Bitmap, che non sono usa e getta. Dovresti assegnare un singolo WriteableBitmap
e aggiornarlo. La documentazione collegata descrive il processo dietro di blocco, l'aggiornamento, e lo sblocco di un WriteableBitmap
Il software lavoro sull'utilizzo di immagini ecografiche in tempo reale in WPF, sto ricevendo un Windows Form Bitmap, che copio nella WriteableBitmap direttamente utilizzando il CopyMemory nativo metodo. Anche con questo lavoro più complicato, la CPU non è eccessivamente tesa e l'utilizzo della memoria non si sposta mai fino a quando dispongo correttamente di ciò che posso. Speriamo che questo esempio può aiutare a:
// DLL returns images as a WinForms Bitmap
Bitmap bmp = myClass.getWinFormsBitmap();
// In my situation, the images are always 640 x 480.
BitmapData data = bmp.LockBits(new Rectangle(0, 0, 640, 480), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
this.writeableBitmap.Lock();
// Copy the bitmap's data directly to the on-screen buffers
NativeMethods.CopyMemory(this.writeableBitmap.BackBuffer, data.Scan0, ImageBufferSize);
// Moves the back buffer to the front.
this.writeableBitmap.AddDirtyRect(new Int32Rect(0, 0, 640, 480));
this.writeableBitmap.Unlock();
bmp.UnlockBits(data);
// Free up the memory of the WinForms bitmap
bmp.Dispose();
Dove CopyMemory è definito come:
[DllImport("Kernel32.dll", EntryPoint = "RtlMoveMemory")]
public static extern void CopyMemory(IntPtr Destination, IntPtr Source, int Length);
fonte
2010-03-16 14:30:22
testarlo e farti sapere, grazie! – John
fantastico !! funziona alla grande grazie! – John
perché non stai usando il metodo WritePixels su WriteableBitmap? Solo se c'è una ragione specifica. – nietras