Need Help Calculating Color Values-Collection of common programming errors
.png)
msdn I want to add a bitmap (with optional transparency) on top of another bitmap. I can’t find anything that simply says Bitmap.DrawImage, so I decided i have to do it on my own. Could someone please give me a formula (or code) that lets me calculate the ARGB value of two colors (the colors can be transparent)? Wouldn’t it some how be a weighted average?Thanks,Ryan-
4 Answers
.png)
msdn1 You can use DrawImage on a Bitmap by way of Graphics.FromImage:Bitmap bmp = new Bitmap(100,100); using (Graphics g = Graphics.FromImage(bmp)) { g.DrawImage(…); } .png)
msdn2Just draw the one bitmap on top of the other. Trying to calculate and write the effective pixel values will be at least an order of magnitude slower. Hans Passant.
.png)
msdn3 What does the using () {} do? I’m going to try it out but I’d like to know what my code is doing.Thanks! I found the answer to color blending on another thread but this works so much faster! I guess i have to learn the using command in normal code!.png)
msdn4 The using statement calls the object’s Dispose() method once the using block ends, which helps free up resources. This only applies to objects that implement the IDisposable interface.So instead of manually calling g.Dispose(), wrapping it in a using statement will take care of this for you and means you do not need to use a try/finally block to ensure Dispose() gets called in case of a runtime exception being thrown.For more info refer to: http://msdn.microsoft.com/en-us/library/yh598w02.aspx
Document my code? Why do you think it’s called “code”?