Re: Near-opaque Alpha Values Fail to Retain Color on Copy

From: Bob Powell [MVP] (bob_at__spamkiller_bobpowell.net)
Date: 05/17/04


Date: Mon, 17 May 2004 11:53:36 +0200

The colour value isn't changing after copy. The values in bmpCopy are
exactly the same.

The value *is* changing after you draw the copied bitmap to the graphics but
that is to be expected because you're drawing a semi opaque pixel which is
being copied using the alpha blending formula. In fact you're drawing a semi
opaque value onto another semi opaque pixel which is even more complex.

If you run your messagebox on the bmpCopy you'll see that the copy was
faithful.

This isn't a bug.

-- 
Bob Powell [MVP]
Visual C#, System.Drawing
Image transition effects, automatic persistent configuration and
design time mouse operations all in April's issue of Well Formed
http://www.bobpowell.net/wellformed.htm
Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm
The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml
Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml
Bob's Blog: http://royo.is-a-geek.com/siteFeeder/GetFeed.aspx?FeedId=41
"BlueMonkMN" <BlueMonkMN@email.com> wrote in message
news:f1299d49.0405160658.78ad528b@posting.google.com...
> I posted earlier about a problem with combining alpha values, but I
> have simplified the problem much more.  Take a look at the red value
> magically changing when I try to make an exact copy of an image with
> near-opaque alpha values.  This must be a GDI+ bug.  Is there a
> work-around or fix?
>
> using System;
> using System.Drawing;
> using System.Drawing.Imaging;
> using System.Drawing.Drawing2D;
> using System.Windows.Forms;
>
> namespace Alpha
> {
>    public class AlphaProblem
>    {
>       public static void Main()
>       {
>          Bitmap bmp = new Bitmap(3,3,PixelFormat.Format32bppArgb);
>          Brush bru = new SolidBrush(Color.FromArgb(254,255,0,0));
>          Graphics g = Graphics.FromImage(bmp);
>          g.FillRectangle(bru,0,0,3,3);
>          MessageBox.Show("Red = " +
>             bmp.GetPixel(1,1).R.ToString(), "Before Copy");
>          Bitmap bmpCopy = (Bitmap)bmp.Clone();
>          g.CompositingMode = CompositingMode.SourceCopy;
>          g.DrawImageUnscaled(bmpCopy,0,0);
>          MessageBox.Show("Red = " +
>             bmp.GetPixel(1,1).R.ToString(), "After Copy");
>          g.Dispose();
>          bru.Dispose();
>          bmpCopy.Dispose();
>          bmp.Dispose();
>       }
>    }
> }


Relevant Pages

  • Re: GdipCreateHBITMAPFromBitmap + PixelFormat32bppARGB
    ... The Windows bitmap specification was drawn up for Windows 3.1 ... Alpha blended bitmaps were not supported. ... The documentation for AlphaBlend function implies that Windows GDI ... an alpha channel. ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: UpdateLayeredWindow major oversight
    ... They do; GDI+. ... As far as populating the high byte goes, if they simply wrote the alpha value of whatever colour you're rendering then ... Your "reverse the alpha channel" is a good suggestion for GDI drawing only, ... telling which pixels were a legit PNG zero-alpha and which were GDI (unless I ...
    (microsoft.public.win32.programmer.gdi)
  • Re: IVMRVideoStreamControl::Set* dont work?
    ... overlay bitmap that I mix onto the VMR rather having a separate source ... Then maybe Since I anyway have to do per pixel alpha, ... filter or assume a single 720x480 bitmap onto which i draw all the ... Is there any way to make the GDI draw on ARGBs and apply an alpha? ...
    (microsoft.public.win32.programmer.directx.video)
  • Re: UpdateLayeredWindow major oversight
    ... If you can't use GDI drawing functions then ... DC without destroying the alpha and thus making UpdateLayeredWindow useless. ... fill the first DIB section with black ...
    (microsoft.public.win32.programmer.gdi)

Loading