C# Resized images have black borders

前端 未结 9 1254
长发绾君心
长发绾君心 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:54

    The problem lies in the fact that your bitmap toReturn has a black background by default. Copying a new image over it makes black or gray borders.

    The solution is to remove the black default background, by calling:

    toReturn.MakeTransparent();
    

    Since after this line you'll be drawing on a new image without any background color the borders will disappear.

提交回复
热议问题