Overlay Transpancy Colour on Image RRS feed

  • Question

  • User-719141508 posted

    Im having a little issue. Basically I want some code to take a Image

    "Image UploadedImage = Image.FromFile(Original);"

    And overlay the colour white with 50% transpancy over the whole thing and then save it back to its current location..

    Ive looked into it and seems I need to apply a rectangle of which has the white/transpacny colour over the whole of the image. But im having issues with it.

    One of the main problems with getting a object Image to work with a graphic object.. Does anyone have the code to do something like this??

    thx in advance steve

    Monday, February 1, 2010 9:39 AM


  • User1211441112 posted

    using System.Drawing;
    using System.Drawing.Drawing2D;

            public static void ResizeStream(int imageSize, Stream filePath, string outputPath)
                var image = Image.FromStream(filePath);

                int thumbnailSize = imageSize;
                int newWidth, newHeight;

                if (image.Width > image.Height)
                    newWidth = thumbnailSize;
                    newHeight = image.Height * thumbnailSize / image.Width;
                    newWidth = image.Width * thumbnailSize / image.Height;
                    newHeight = thumbnailSize;

                var thumbnailBitmap = new Bitmap(newWidth, newHeight);

                var thumbnailGraph = Graphics.FromImage(thumbnailBitmap);
                thumbnailGraph.CompositingQuality = CompositingQuality.HighQuality;
                thumbnailGraph.SmoothingMode = SmoothingMode.HighQuality;
                thumbnailGraph.InterpolationMode = InterpolationMode.HighQualityBicubic;

                var imageRectangle = new Rectangle(0, 0, newWidth, newHeight);
                thumbnailGraph.DrawImage(image, imageRectangle);

                Color color = Color.FromArgb(50, 255, 255, 255);
                SolidBrush brush = new SolidBrush(color);
                Point atPoint = new Point(10, 10);
                Pen pen=new Pen(brush);
                thumbnailGraph.FillRectangle(brush, imageRectangle);


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, February 3, 2010 1:38 AM