Amsath
Amsath

Reputation: 81

Need to know the difference between the Bitmap's pixel format Format32bppArgb and Format24bppRgb

I have an issue with .net controls while saving them as images. when i export the Panel control as image with bitmap's Pixel format 'Format24bppRgb' then a Gray border is shown in the image but it is not shown when i export it using the pixelformat 'Format32bppArgb'. I dont know why the gray border is visible in the image. Can any one help me on this?

Here is the code which is used to export image:

 using (Bitmap bmp = new Bitmap((int)panel1.Width, (int)panel1.Height,PixelFormat.Format24bppRgb))
        {
            System.Drawing.Rectangle rect = new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height);
            using (Graphics g = Graphics.FromImage(bmp))
            {
                g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                using (Brush brushFill = diagram1.Model.BackgroundStyle.CreateBrush(g, rect))
                {
                    g.FillRectangle(brushFill, Geometry.ConvertRectangle(rect));

                }

                bmp.Save(@"..//..//bitmap.png", ImageFormat.Png);
            }
        }

Here is the image i have created with format Format24bppRgb enter image description here

Here is the image i have created with format Format32bppArgb enter image description here

Thanks is advance........................

Upvotes: 0

Views: 6268

Answers (2)

Xiaohuan ZHOU
Xiaohuan ZHOU

Reputation: 586

Format24bppRgb is Red, Green and Blue values of each pixel. At 8 bits per color (0 ~ 255)

Format32bppArgb is Alpha, Red, Green and Blue values of each pixel. At 8 bits per color (0 ~ 255). Alpha is for transparent effect. You can set Graphics.CompositingMode = CompositingMode.SourceOver; to get the transparent effect, show as the following pic:enter image description here

Upvotes: 1

ChrisF
ChrisF

Reputation: 137188

Format24bppRgb is just the Red, Green and Blue values of each pixel. At 8 bits per colour you get 24 bits per pixel.

Format32bppArgb include an Alpha (or transparency) value for each pixel. This is an extra 8 bits per pixel so you get a total of 32 bits per pixel.

There's a border on the second image as well - it's seems to be a dotted and a lot fainter than on the first. This must be an artefact of the saving process and must be fainter in the second case because of the alpha channel.

Upvotes: 2

Related Questions