可能有抗锯齿绘制截取图像时? [英] Possible to have anti-aliasing when drawing a clipped image?

查看:227
本文介绍了可能有抗锯齿绘制截取图像时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我成功地使用 图形绘制一个非矩形截取图像(龟内):

Currently, I'm successfully using the Graphics class to draw a non-rectangular clipped image (the turtle inside):

我的code看起来是这样的:

My code looks something like:

using (var g = Graphics.FromImage(image))
{
    g.InterpolationMode = InterpolationMode.HighQualityBicubic;

    using (var gfxPath = new GraphicsPath())
    {
        gfxPath.AddEllipse(r);

        using (var region = new Region(r))
        {
            region.Exclude(gfxPath);

            g.ExcludeClip(region);

            g.DrawImage(turtleImage, r, r2, GraphicsUnit.Pixel);
        }
    }
}

这正如预期的所有作品。我不知道怎么解决是使图像边缘抗锯齿。

This all works just as expected. What I do not know how to solve is to make the image border anti-aliased.

图片缩放是这样的:

即。其中图像结束,开始图像的透明的背景的边界是一个粗剪,不光滑的α混合

I.e. the border where the image ends and the transparent "background" of the image starts is a rough cut, not a smooth alpha blending.

我的问题是:

是否有可能夹了绘制的图像,并具有抗锯齿模式了吗?

Is it possible to clip a drawn image and having anti-aliasing active?

推荐答案

如果你想要去的完全成熟羽化,你应该考虑一下这篇文章:

If you want to go for full blown feathering you should consider taking a look at this article:

http://danbystrom.se/2008/08 / 24 /软边 - 图像 - 在-GDI /

如果你想有一个快速简便的解决方案,你也许可以借鉴的形象第一次再画使用的是纯白色画笔抗锯齿在它上面的一个GraphicsPath的。你会做这样的事情:

If you want a quick and easy solution you could probably draw the image first then draw a GraphicsPath on top of it using a solid white brush with antialiasing. You would do something like this:

Rectangle outerRect = ClientRectangle;
Rectangle rect = Rectangle.Inflate(outerRect, -20, -20);

using (Image img = new Bitmap("test.jpg"))
{
    g.DrawImage(img, outerRect);

    using (SolidBrush brush = new SolidBrush(Color.White))
    using (GraphicsPath path = new GraphicsPath())
    {
        g.SmoothingMode = SmoothingMode.AntiAlias;

        path.AddEllipse(rect);
        path.AddRectangle(outerRect);

        g.FillPath(brush, path);
    }
}

这篇关于可能有抗锯齿绘制截取图像时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆