[Mono-osx] (no subject)

David Black David.Black at casewise.com
Sun Aug 5 16:07:08 UTC 2012


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

              byte [] data = new byte[(width*3)*height] ;
              var ptr = 0;
              for (int y=0; y<height; y++)
              {
                   for (int x=0; x<width; x++)
                   {
                        Rgba p = _pixels[x,y];
                        p.Clamp();
                        data[ptr++] = (byte)(p.values[0] * 255);
                        data[ptr++] = (byte)(p.values[1] * 255);
                        data[ptr++] = (byte)(p.values[2] * 255);
                   }
              }
              Bitmap bmp = new System.Drawing.Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);

              BitmapData bmpData = bmp.LockBits(
                       new System.Drawing.Rectangle(0, 0, width, height),
                       ImageLockMode.WriteOnly,
                   bmp.PixelFormat);

                //Copy the data from the byte array into BitmapData.Scan0
                Marshal.Copy(data, 0, bmpData.Scan0, data.Length);

                //Unlock the pixels
                bmp.UnlockBits(bmpData);
              return bmp

(values[0]..[2] is rgb)

When I changed it to

                        data[ptr++] = (byte)(p.values[2] * 255);
                        data[ptr++] = (byte)(p.values[1] * 255);
                        data[ptr++] = (byte)(p.values[0] * 255);

It worked. It looks like 24bppRgb is being interpreted as 24bppBgr ???

Has anyone seen this (or am I being an idiot and doing it wrong)

D
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/mono-osx/attachments/20120805/fa90d705/attachment.html>


More information about the Mono-osx mailing list