Resize bitmap like in MS Paint

后端 未结 6 1614
北恋
北恋 2021-01-20 12:23

I need to resize a bmp like the resize works in MS Paint - that is with no antialiasing . Anyone know how to do this in c# or vb.net ?

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-20 12:55

    You can set the graphics interpolation mode to nearest neighbor and then use drawimage to resize it without anti-aliasing. (pardon my vb :-) )

    Dim img As Image = Image.FromFile("c:\jpg\1.jpg")
    Dim g As Graphics
    
    pic1.Image = New Bitmap(180, 180, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
    g = Graphics.FromImage(pic1.Image)
    g.InterpolationMode = Drawing2D.InterpolationMode.NearestNeighbor
    g.DrawImage(img, 0, 0, pic1.Image.Width, pic1.Image.Height)
    

提交回复
热议问题