{"id":4568,"date":"2014-03-30T13:33:17","date_gmt":"2014-03-30T13:33:17","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/need-help-calculating-color-values-collection-of-common-programming-errors\/"},"modified":"2014-03-30T13:33:17","modified_gmt":"2014-03-30T13:33:17","slug":"need-help-calculating-color-values-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/need-help-calculating-color-values-collection-of-common-programming-errors\/","title":{"rendered":"Need Help Calculating Color Values-Collection of common programming errors"},"content":{"rendered":"<ul>\n<li><img decoding=\"async\" src=\"http:\/\/i.msdn.microsoft.com\/dn186180.LOGO_Win1211(id-id,MSDN.10).png\" \/><br \/>\nmsdn I want to add a bitmap (with optional transparency) on top of another bitmap. I can&#8217;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&#8217;t it some how be a weighted average?Thanks,Ryan<\/li>\n<li>\n<h3>4 Answers<\/h3>\n<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.msdn.microsoft.com\/dn186180.LOGO_Win1211(id-id,MSDN.10).png\" \/><br \/>\nmsdn1 You can use DrawImage on a Bitmap by way of Graphics.FromImage:<\/p>\n<table>\n<tr>\n<td>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Bitmap\u00a0bmp\u00a0=\u00a0new\u00a0Bitmap(100,100); \u00a0<\/td>\n<\/tr>\n<tr>\n<td>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0using\u00a0(Graphics\u00a0g\u00a0=\u00a0Graphics.FromImage(bmp)) \u00a0<\/td>\n<\/tr>\n<tr>\n<td>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{ \u00a0<\/td>\n<\/tr>\n<tr>\n<td>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0g.DrawImage(&#8230;); \u00a0<\/td>\n<\/tr>\n<tr>\n<td>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\u00a0<\/td>\n<\/tr>\n<\/table>\n<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.msdn.microsoft.com\/dn186180.LOGO_Win1211(id-id,MSDN.10).png\" \/><br \/>\nmsdn2<\/p>\n<p>Just draw the one bitmap on top of the other.\u00a0 Trying to calculate and write the effective pixel values will be at least an order of magnitude slower. Hans Passant.<\/p>\n<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.msdn.microsoft.com\/dn186180.LOGO_Win1211(id-id,MSDN.10).png\" \/><br \/>\nmsdn3 What does the using () {} do? I&#8217;m going to try it out but I&#8217;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!<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.msdn.microsoft.com\/dn186180.LOGO_Win1211(id-id,MSDN.10).png\" \/><br \/>\nmsdn4 The using statement calls the object&#8217;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.<\/p>\n<p>For more info refer to: http:\/\/msdn.microsoft.com\/en-us\/library\/yh598w02.aspx<\/p>\n<p>\nDocument my code? Why do you think it&#8217;s called &#8220;code&#8221;?<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>msdn I want to add a bitmap (with optional transparency) on top of another bitmap. I can&#8217;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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4568","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4568","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=4568"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4568\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=4568"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=4568"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=4568"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}