Unable to convert image object that uses drawing for content to a bitmap
<p>Thoughts on why the following is resulting in a null bitmap? </p>

<p>frame_image is a image object that uses a drawing for content</p>

<pre><code>private void Bitmapcreate(this)
{

RenderTargetBitmap targetBitmap = new RenderTargetBitmap((int)frame_image.ActualWidth,(int)frame_image.ActualHeight,96d, 96d,Media.PixelFormats.Pbgra32);

targetBitmap.Render(frame_image);


MemoryStream mse = new MemoryStream();

System.Windows.Media.Imaging.

BmpBitmapEncoder mem = new BmpBitmapEncoder();

mem.Frames.Add(BitmapFrame.Create(targetBitmap));

mem.Save(mse);

mse.Position = 0;


BitmapImage bi = new BitmapImage();

bi.BeginInit();

bi.StreamSource = mse;

bi.EndInit();


Bitmap b = new Bitmap(BitmapSourceToBitmap(bi)); // b is turning out to be null. 

} 


public static System.Drawing.Bitmap BitmapSourceToBitmap(BitmapSource srs)

{

System.Drawing.Bitmap btm = null;


int width = srs.PixelWidth;


int height = srs.PixelHeight;


int stride = width * ((srs.Format.BitsPerPixel + 7) / 8);


IntPtr ptr = Marshal.AllocHGlobal(height * stride);

srs.CopyPixels(new Int32Rect(0, 0, width, height), ptr, height * stride, stride);

btm = new System.Drawing.Bitmap(width, height, stride, System.Drawing.Imaging.PixelFormat.Format1bppIndexed, ptr);


return btm;

}
</code></pre>
