I use always using
You are not. Unfortunately you also use it when you should not. There are three bitmap objects being 'leaked' here for every frame.
You got in trouble by using using on the MemoryStream. And patched the problem by copying the bitmap, but the bitmap object is not being disposed. Fix this the right way, do not dispose the MemoryStream. Not disposing the MemoryStream is fine, it only uses memory and has no disposable members when you don't use the MemoryStream(Stream) constructor. Now you don't need the copy you make with the Bitmap(image) constructor anymore either. That's one.
The bitmap returned by BitmapImage2Bitmap() is not being disposed. That's two.
The bitmap returned by ResizeBitmap() is not being disposed. That's three.
It should look like this:
using (var frame = BitmapImage2Bitmap(e.ColorFrame.BitmapImage))
using (var thumb = ResizeBitmap(frame, 320, 240)) {
writer.WriteVideoFrame(thumb);
}
and:
private Bitmap BitmapImage2Bitmap(BitmapImage bitmapImage)
{
var outStream = new MemoryStream();
var enc = new BmpBitmapEncoder();
enc.Frames.Add(BitmapFrame.Create(bitmapImage));
enc.Save(outStream);
return new System.Drawing.Bitmap(outStream);
}
You may well still have a firehose problem as I mentioned in the comment, this code certainly is faster than the original by avoiding the bitmap copy but still won't burn rubber.