C# Resized images have black borders

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

    None of these worked for me.

    However, changing the format from

    System.Drawing.Imaging.PixelFormat.Format24bppRgb
    

    to

    System.Drawing.Imaging.PixelFormat.Format32bppArgb 
    

    did solve the problem

    using (System.Drawing.Bitmap newImage = new System.Drawing.Bitmap(newWidth, newHeight,
                    // System.Drawing.Imaging.PixelFormat.Format24bppRgb // OMG bug
                        System.Drawing.Imaging.PixelFormat.Format32bppArgb 
                    ))
                {
    

提交回复
热议问题