1

I have a byte-array of pixels and a color-palette representing a 256-color palette-indexed Windows-bitmap. I need to create OSX NSImage from that.

In Windows its just:

public Bitmap CreateFromData(byte[] buffer, int width, int height, byte[] palette3x256)
    {
       //allocate new bitmap
       Bitmap img = new Bitmap(width, height, PixelFormat.Format8bppIndexed);

       //fill image palette with color information
       ColorPalette pal = img.Palette;
       for (int i = 0; i < palette3x256.Length; i += 3)
           pal.Entries[i / 3] = Color.FromArgb(palette3x256[i + 2], palette3x256[i + 1], palette3x256[i]);
       img.Palette = pal;

       // copy pixels to bitmap
       BitmapData data = img.LockBits(new Rectangle(0, 0, img.Width, img.Height), ImageLockMode.WriteOnly, img.PixelFormat);
       Marshal.Copy(buffer, 0, data.Scan0, buffer.Length);
       img.UnlockBits(data);

      return img;
    }

How would I do this in OSX-Xamarin? I need to create a NSImage or NSBitmapImageRep? Unfortunally I'm not very familiar with these native OSX-things.

Tom
  • 190
  • 3
  • 18

0 Answers0