I haven't specifically looked t the mono implementation for bitmaps, but the .net 24-bit bitmaps have each pixel word-aligned rather than packed into consecutive bytes. After that I'd check for channel ordering of bytes.<div>
<br></div><div>Pete<span></span><br><br>On Sunday, August 5, 2012, David Black  wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div lang="EN-GB" link="blue" vlink="purple">
<div><p class="MsoNormal" style="text-autospace:none"><span style="font-size:12.0pt;font-family:"Helvetica","sans-serif""><u></u> <u></u></span></p><p class="MsoNormal" style="text-autospace:none"><span style="font-size:12.0pt;font-family:"Helvetica","sans-serif"">My application ray traces a 3D scene into a 2d array and then converts the result to a bitmap. The following code was producing colour shifted images<u></u><u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:12.0pt;font-family:"Helvetica","sans-serif""><u></u> <u></u></span></p><p class="MsoNormal" style="text-autospace:none"><span style="font-size:12.0pt;font-family:Monaco">              <span style="color:#0025ff">byte</span> [] data = <span style="color:#0025ff">new</span> <span style="color:#0025ff">byte</span>[(width*<span style="color:#cc0ecb">3</span>)*height] ;<u></u><u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:12.0pt;font-family:Monaco">              <span style="color:#0025ff">var</span> ptr = <span style="color:#cc0ecb">0</span>;<u></u><u></u></span></p><p class="MsoNormal" style="text-autospace:none">
<span style="font-size:12.0pt;font-family:Monaco">              <span style="color:#0025ff">for</span> (<span style="color:#0025ff">int</span> y=<span style="color:#cc0ecb">0</span>; y<height; y++)<u></u><u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:12.0pt;font-family:Monaco">              {<u></u><u></u></span></p><p class="MsoNormal" style="text-autospace:none"><span style="font-size:12.0pt;font-family:Monaco">                   <span style="color:#0025ff">for</span> (<span style="color:#0025ff">int</span> x=<span style="color:#cc0ecb">0</span>; x<width; x++)<u></u><u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:12.0pt;font-family:Monaco">                   {<u></u><u></u></span></p><p class="MsoNormal" style="text-autospace:none"><span style="font-size:12.0pt;font-family:Monaco">                        Rgba p = _pixels[x,y];<u></u><u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:12.0pt;font-family:Monaco">                        p.Clamp();<u></u><u></u></span></p><p class="MsoNormal" style="text-autospace:none"><span style="font-size:12.0pt;font-family:Monaco">                        data[ptr++] = (<span style="color:#0025ff">byte</span>)(p.values[<span style="color:#cc0ecb">0</span>] * <span style="color:#cc0ecb">255</span>);<u></u><u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:12.0pt;font-family:Monaco">                        data[ptr++] = (<span style="color:#0025ff">byte</span>)(p.values[<span style="color:#cc0ecb">1</span>] * <span style="color:#cc0ecb">255</span>);<u></u><u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:12.0pt;font-family:Monaco">                        data[ptr++] = (<span style="color:#0025ff">byte</span>)(p.values[<span style="color:#cc0ecb">2</span>] * <span style="color:#cc0ecb">255</span>);<u></u><u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:12.0pt;font-family:Monaco">                   }<u></u><u></u></span></p><p class="MsoNormal" style="text-autospace:none"><span style="font-size:12.0pt;font-family:Monaco">              }<u></u><u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:12.0pt;font-family:Monaco">              Bitmap bmp = <span style="color:#0025ff">new</span> System.Drawing.Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);<u></u><u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:12.0pt;font-family:Monaco"><u></u> <u></u></span></p><p class="MsoNormal" style="text-autospace:none"><span style="font-size:12.0pt;font-family:Monaco">              BitmapData bmpData = bmp.LockBits(<u></u><u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:12.0pt;font-family:Monaco">                       <span style="color:#0025ff">new</span> System.Drawing.Rectangle(<span style="color:#cc0ecb">0</span>, <span style="color:#cc0ecb">0</span>, width, height),   <u></u><u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:12.0pt;font-family:Monaco">                       ImageLockMode.WriteOnly, <u></u><u></u></span></p><p class="MsoNormal" style="text-autospace:none">
<span style="font-size:12.0pt;font-family:Monaco">                   bmp.PixelFormat);<u></u><u></u></span></p><p class="MsoNormal" style="text-autospace:none"><span style="font-size:12.0pt;font-family:Monaco"> <u></u><u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:12.0pt;font-family:Monaco">                <span style="color:#339901">//Copy the data from the byte array into BitmapData.Scan0<u></u><u></u></span></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:12.0pt;font-family:Monaco">                Marshal.Copy(data, <span style="color:#cc0ecb">0</span>, bmpData.Scan0, data.Length);<u></u><u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:12.0pt;font-family:Monaco">                             <u></u><u></u></span></p><p class="MsoNormal" style="text-autospace:none"><span style="font-size:12.0pt;font-family:Monaco">                <span style="color:#339901">//Unlock the pixels<u></u><u></u></span></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:12.0pt;font-family:Monaco">                bmp.UnlockBits(bmpData);<u></u><u></u></span></p><p class="MsoNormal" style="text-autospace:none"><span style="font-size:12.0pt;font-family:Monaco">              <span style="color:#0025ff">return</span> bmp<u></u><u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:12.0pt;font-family:"Helvetica","sans-serif""><u></u> <u></u></span></p><p class="MsoNormal" style="text-autospace:none"><span style="font-size:12.0pt;font-family:"Helvetica","sans-serif"">(values[0]..[2] is rgb)<u></u><u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:12.0pt;font-family:"Helvetica","sans-serif""><u></u> <u></u></span></p><p class="MsoNormal" style="text-autospace:none"><span style="font-size:12.0pt;font-family:"Helvetica","sans-serif"">When I changed it to <u></u><u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:12.0pt;font-family:"Helvetica","sans-serif""><u></u> <u></u></span></p><p class="MsoNormal" style="text-autospace:none"><span style="font-size:12.0pt;font-family:Monaco">                        data[ptr++] = (<span style="color:#0025ff">byte</span>)(p.values[<span style="color:#cc0ecb">2</span>] * <span style="color:#cc0ecb">255</span>);<u></u><u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:12.0pt;font-family:Monaco">                        data[ptr++] = (<span style="color:#0025ff">byte</span>)(p.values[<span style="color:#cc0ecb">1</span>] * <span style="color:#cc0ecb">255</span>);<u></u><u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:12.0pt;font-family:Monaco">                        data[ptr++] = (<span style="color:#0025ff">byte</span>)(p.values[<span style="color:#cc0ecb">0</span>] * <span style="color:#cc0ecb">255</span>);<u></u><u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:12.0pt;font-family:"Helvetica","sans-serif""><u></u> <u></u></span></p><p class="MsoNormal" style="text-autospace:none"><span style="font-size:12.0pt;font-family:"Helvetica","sans-serif"">It worked. It looks like 24bppRgb is being interpreted as 24bppBgr ???<u></u><u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:12.0pt;font-family:"Helvetica","sans-serif""><u></u> <u></u></span></p><p class="MsoNormal" style="text-autospace:none"><span style="font-size:12.0pt;font-family:"Helvetica","sans-serif"">Has anyone seen this (or am I being an idiot and doing it wrong)<u></u><u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:12.0pt;font-family:"Helvetica","sans-serif""><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:12.0pt;font-family:"Helvetica","sans-serif"">D</span><u></u><u></u></p>
</div></div></blockquote></div>