C# Resized images have black borders

前端 未结 9 1257
长发绾君心
长发绾君心 2020-12-15 08:58

I have a problem with image scaling in .NET. I use the standard Graphics type to resize images like in this example:

public static Image Scale(Image sourceIm         


        
9条回答
  •  时光取名叫无心
    2020-12-15 09:49

    The real solution is to use an overload of the DrawImage which allows you to pass a ImageAttributes object.

    On the ImageAttributes instance, call the following method before passing it to DrawImage:

    using (var ia = new ImageAttributes())
    {
        ia.SetWrapMode(WrapMode.TileFlipXY);
        aGraphic.DrawImage(..., ia);
    }
    

    See also this answer

提交回复
热议问题