[Mono-osx] (no subject)

Pete Bergstrom petebergstrom at gmail.com
Sun Aug 5 18:02:26 UTC 2012


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.

Pete

On Sunday, August 5, 2012, David Black wrote:

> ** **
>
> 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/9f7dbed1/attachment-0001.html>


More information about the Mono-osx mailing list