Re: Near-opaque Alpha Values Fail to Retain Color on Copy
From: Bob Powell [MVP] (bob_at__spamkiller_bobpowell.net)
Date: 05/17/04
- Next message: Bob Powell [MVP]: "Re: VB - saving files with encoders"
- Previous message: JK: "Printing on different platforms"
- In reply to: BlueMonkMN: "Near-opaque Alpha Values Fail to Retain Color on Copy"
- Next in thread: BlueMonkMN: "Re: Near-opaque Alpha Values Fail to Retain Color on Copy"
- Reply: BlueMonkMN: "Re: Near-opaque Alpha Values Fail to Retain Color on Copy"
- Messages sorted by: [ date ] [ thread ]
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(); > } > } > }
- Next message: Bob Powell [MVP]: "Re: VB - saving files with encoders"
- Previous message: JK: "Printing on different platforms"
- In reply to: BlueMonkMN: "Near-opaque Alpha Values Fail to Retain Color on Copy"
- Next in thread: BlueMonkMN: "Re: Near-opaque Alpha Values Fail to Retain Color on Copy"
- Reply: BlueMonkMN: "Re: Near-opaque Alpha Values Fail to Retain Color on Copy"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|
Loading