Re[4]: Конвертация метафайла в bmp
От: Wise_PingWin  
Дата: 02.11.11 07:25
Оценка:
Здравствуйте, Legion13, Вы писали:

L>Здравствуйте, Аноним, Вы писали:


А>>Здравствуйте, Legion13, Вы писали:


L>>>А если интерполяцию отключить?

А>>А как его отключить не подскажите?

L>Попробуйте закомментарить вот этот код:

L>
L>myGraphics.SmoothingMode = SmoothingMode.HighQuality;
L>myGraphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
L>myGraphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
L>myGraphics.CompositingQuality = CompositingQuality.HighQuality;
L>



Здесь так не прокатит. Информация о том как сглаживать (и вообще, как рисовать) векторное изображение находится в самом metafile'е, настройки myGraphics на качество отрисовки никак не влияют никак не влияют.
Пример:
private static Metafile CreateNewMetafile()
{
    Metafile result;
    using (Bitmap b = new Bitmap(1, 1))
    using (Graphics g = Graphics.FromImage(b))
    using (MemoryStream ms = new MemoryStream())
    {
        IntPtr ipHdc = g.GetHdc();
        result = new Metafile(ms, ipHdc, EmfType.EmfPlusOnly);
        g.ReleaseHdc(ipHdc);
    }
    return result;
}

private static Metafile TestGraphic(bool smoothing)
{
    var result = CreateNewMetafile();
    using (Graphics graphics = Graphics.FromImage(result))
    {
        graphics.SmoothingMode = smoothing ? SmoothingMode.HighQuality : SmoothingMode.None;
        //оси
        using (Pen pen = new Pen(Color.Black, 2))
        {
            graphics.DrawLine(pen, new Point(0, 1000), new Point(0, 0));
            graphics.DrawLine(pen, new Point(0, 1000), new Point(1000, 1000));
        }
        //типо график
        graphics.DrawLine(Pens.Black, new Point(0, 700), new Point(400, 700));
        graphics.DrawArc(Pens.Black, new Rectangle(new Point(300, 500), new Size(200, 200)), 0, 90);
        graphics.DrawArc(Pens.Black, new Rectangle(new Point(500, 500), new Size(200, 200)), 180, 180);
        graphics.DrawLine(Pens.Black, new Point(700, 600), new Point(1000, 1000));
    }
    return result;
}

private static void DrawPng(Metafile meta, int width, int height)
{
    using (Bitmap bmp = new Bitmap(width, height))
    using (Graphics graphics = Graphics.FromImage(bmp))
    {
        Rectangle rcSrc = new Rectangle(0, 0, meta.Width, meta.Height);
        Rectangle rcDest = new Rectangle(0, 0, bmp.Width, bmp.Height);

        graphics.SmoothingMode = SmoothingMode.None;
        graphics.InterpolationMode = InterpolationMode.Low;

        graphics.DrawImage(meta, rcDest, rcSrc, GraphicsUnit.Pixel);
        bmp.Save(@"C:\png.png");
    }
}

[STAThread]
public static void Main(string[] args)
{
    using (var meta = TestGraphic(true))
    {
        meta.Save(@"C:\meta.wmf");
        DrawPng(meta, 10000, 10000);
    }
}
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.