在.net中抗锯齿2色调位图而不缩小

时间:2016-05-14 17:08:53

标签: .net vb.net bitmap antialiasing

是否有办法在不缩小图像的情况下对2色调位图(在.NET中)进行抗锯齿处理。例如,我有一个黑白图像,黑色物体有锯齿状边缘。我想平滑“非白色”对象的边缘,而不缩小整个位图。

以下是我目前正在执行的操作:

Dim from_bm = New Bitmap(frm.ClientSize.Width, frm.ClientSize.Height)
Dim bm_gr As Graphics = Graphics.FromImage(from_bm)
Dim bm_hdc As IntPtr = bm_gr.GetHdc

BitBlt(bm_hdc, 0, 0, frm.ClientSize.Width, frm.ClientSize.Height, hdc, 0, 0, SRCCOPY)
bm_gr.ReleaseHdc(bm_hdc)

Dim w As Integer = (from_bm.Width / 4) ' This is the operation I wish to avoid
Dim h As Integer = (from_bm.Height / 4)
to_bm = New Bitmap(w, h)

Dim gr As Graphics = Graphics.FromImage(to_bm)
gr.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
gr.DrawImage(from_bm, 0, 0, (w - 1), (h - 1))
gr.DrawImageUnscaled(to_bm, 0, 0)

我想知道是否有一些算法或库我可以用来执行上述操作,但不会缩小上面的图像。我之所以希望避免缩小图像,是因为我无法将完整的位图保存到内存中,我只能保存显示在屏幕上的内容,这对我来说是个问题。

1 个答案:

答案 0 :(得分:0)

我不确定你理解你的意思,但我认为你可以使用以下方法设置图形的插值模式:

graphic.InterpolationMode = InterpolationMode.NearestNeighbor