locked
Remove background color from Graphics.Clear() RRS feed

  • Question

  • User709865310 posted

    HI all,

    I have a code to resize image. it works good just one thing that I dont want. 

     Bitmap bmPhoto = new Bitmap(Width, Height,
                                  PixelFormat.Format24bppRgb);
                bmPhoto.SetResolution(fullSizeImg.HorizontalResolution,
                                 fullSizeImg.VerticalResolution);
    
                Graphics grPhoto = Graphics.FromImage(bmPhoto);
                grPhoto.Clear(Color.Red);
                grPhoto.InterpolationMode = InterpolationMode.Default;
                grPhoto.CompositingQuality = CompositingQuality.HighQuality;
                grPhoto.SmoothingMode = SmoothingMode.HighQuality;
    
                grPhoto.DrawImage(fullSizeImg,
                    new Rectangle(destX, destY, destWidth, destHeight),
                    new Rectangle(sourceX, sourceY, sourceWidth, sourceHeight),
                    GraphicsUnit.Pixel);
    
                grPhoto.Dispose();

    In my bold section, it fills a Red color on outside of image. I dont want that red color. If I remove that line, it fills with black color. I dont want that color at all. I want it fits whatever empty spaces it is getting that filled with color.

    Monday, April 4, 2016 8:30 AM

All replies

  • User-359936451 posted

    Set FillStyle = Transparent

    Wednesday, April 6, 2016 8:36 PM