We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Image smaller than rectangle will make rectangle black

We have a need to have a canvas greater than the size of an image. I am doing this by making the rectangle the correct size and putting image in oversized rectangle. When I do the the parts that the image does not cover are black. Can I change this color. My desire is for it to be white. Please see my code and output.
ImageResizeBackgroundBlack.zip (1.4 MB)

Thanks Charles

@ccuster68 Please try next code to make background color white:

var outputfile = Path.Combine(@"c:\Users\USER\Downloads", "BlackBackground.png");

PngOptions pngOptions = new PngOptions();
pngOptions.Source = new Aspose.Imaging.Sources.FileCreateSource(outputfile, false);

using (var image = Aspose.Imaging.Image.Load(@"LetterSizeJpeg.jpg"))
{
    using (RasterImage image2 = (RasterImage)Image.Create(pngOptions, image.Width + 300, image.Height + 300))
    {
        //Create and initialize an instance of Graphics class
        Aspose.Imaging.Graphics graphics = new Aspose.Imaging.Graphics(image2);

        //Clear Graphics surface
        graphics.Clear(Aspose.Imaging.Color.White);
        graphics.DrawImage(image, new Point(0, 0));


        image2.Save();
    }
}

Thank you Samer. That solved my issue.