Hi, you shoud use the method
RenderTargetBitmap bmp = new RenderTargetBitmap((Int32)Math.Ceiling(width),
(Int32)Math.Ceiling(height),
(Double)DeviceHelper.PixelsPerInch(Orientation.Horizontal),
(Double)DeviceHelper.PixelsPerInch(Orientation.Vertical),
PixelFormats.Pbgra32);
DrawingVisual dv = new DrawingVisual();
..................................
bmp.Render(dv);
bmp is a BitMapSource
Hope this help you
internal class DeviceHelper
{
public static Int32 PixelsPerInch(Orientation orientation)
{
Int32 capIndex = (orientation == Orientation.Horizontal) ? 0x58 : 90;
using (DCSafeHandle handle = UnsafeNativeMethods.CreateDC("DISPLAY"))
{
return (handle.IsInvalid ? 0x60 : UnsafeNativeMethods.GetDeviceCaps(handle, capIndex));
}
}
}
[DllImport("gdi32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern Int32 GetDeviceCaps(DCSafeHandle hDC, Int32 nIndex);
[DllImport("gdi32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern Boolean DeleteDC(IntPtr hDC);
internal sealed class DCSafeHandle : SafeHandleZeroOrMinusOneIsInvalid
{
private DCSafeHandle() : base(true) { }
protected override Boolean ReleaseHandle()
{
return UnsafeNativeMethods.DeleteDC(base.handle);
}
}
Oscar Avarez Guerras - Arquitecto Software en I3B (I+D+I)
Blog:http://geeks.ms/blogs/oalvarez
Por favor marca como respuesta si te ha ayudado esta respuesta