@ dobova - While it is not ideal and is quite slow when compared to their native versions, here are some rough C# versions of those functions. The Mainboard.NativeBitmapConverter line is important because it allows the N18 to function, though slowly, on non-cerb boards. If you still wish to use the TakePicture method of the Camera, you will need to modify the driver and change line 192 to use this temporary ConvertToFile function. https://www.ghielectronics.com/docs/122/gadgeteer-driver-modification can help you with that. The Microsoft.SPOT.Hardware, Microsoft.SPOT.Graphics, and GHI.Hardware assemblies are required.
using GHI.Utilities;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
namespace BitmapFix
{
public partial class Program
{
void ProgramStarted()
{
Mainboard.NativeBitmapConverter = (bmp, buffer, bpp) => Convert(bmp, Bitmaps.BitsPerPixel.BPP16_BGR_BE, buffer);
this.displayN18.Clear();
this.displayN18.SimpleGraphics.AutoRedraw = false;
this.displayN18.SimpleGraphics.DisplayEllipse(Gadgeteer.Color.Red, 1, Gadgeteer.Color.Red, 5, 5, 5, 5);
this.displayN18.SimpleGraphics.DisplayEllipse(Gadgeteer.Color.Green, 1, Gadgeteer.Color.Green, 15, 5, 5, 5);
this.displayN18.SimpleGraphics.DisplayEllipse(Gadgeteer.Color.Blue, 1, Gadgeteer.Color.Blue, 25, 5, 5, 5);
this.displayN18.SimpleGraphics.Redraw();
}
public void Convert(Bitmap bitmap, Bitmaps.BitsPerPixel bpp, byte[] outputBuffer)
{
var inputBuffer = bitmap.GetBitmap();
var inputSize = inputBuffer.Length;
var outputSize = outputBuffer.Length;
if (outputSize < inputSize / 2) throw new System.ArgumentException("outputBuffer.Length must be half of the bitmap size.", "outputSize");
if (bpp != Bitmaps.BitsPerPixel.BPP16_RGB_BE && bpp != Bitmaps.BitsPerPixel.BPP16_RGB_LE && bpp != Bitmaps.BitsPerPixel.BPP16_BGR_BE && bpp != Bitmaps.BitsPerPixel.BPP16_BGR_LE) throw new System.NotImplementedException();
var doSwap = bpp == Bitmaps.BitsPerPixel.BPP16_RGB_BE || bpp == Bitmaps.BitsPerPixel.BPP16_BGR_BE;
var isBGR = bpp == Bitmaps.BitsPerPixel.BPP16_BGR_BE || bpp == Bitmaps.BitsPerPixel.BPP16_BGR_LE;
ushort value;
for (int i = 0, j = 0; i < inputSize; i += 4, j += 2)
{
if (isBGR)
value = (ushort)(((inputBuffer[i] & 0xF8) << 8) | ((inputBuffer[i + 1] & 0xFC) << 3) | (inputBuffer[i + 2] >> 3));
else
value = (ushort)(((inputBuffer[i + 2] & 0xF8) << 8) | ((inputBuffer[i + 1] & 0xFC) << 3) | (inputBuffer[i] >> 3));
if (doSwap)
value = (ushort)(((value & 0xFF00) >> 8) | ((value & 0x00FF) << 8));
Utility.InsertValueIntoArray(outputBuffer, j, 2, value);
}
}
public void ConvertToFile(Bitmap bitmap, byte[] outputBuffer)
{
var inputBuffer = bitmap.GetBitmap();
var width = (uint)bitmap.Width;
var height = (uint)bitmap.Height;
if (outputBuffer.Length != width * height * 3 + 54) throw new System.ArgumentException("outputBuffer.Length must be width * height * 3 + 54.", "outputSize");
System.Array.Clear(outputBuffer, 0, outputBuffer.Length);
Utility.InsertValueIntoArray(outputBuffer, 0, 2, 19778);
Utility.InsertValueIntoArray(outputBuffer, 2, 4, width * height * 3 + 54);
Utility.InsertValueIntoArray(outputBuffer, 10, 4, 54);
Utility.InsertValueIntoArray(outputBuffer, 14, 4, 40);
Utility.InsertValueIntoArray(outputBuffer, 18, 4, width);
Utility.InsertValueIntoArray(outputBuffer, 22, 4, (uint)(-height));
Utility.InsertValueIntoArray(outputBuffer, 26, 2, 1);
Utility.InsertValueIntoArray(outputBuffer, 28, 2, 24);
for (int i = 0, j = 54; i < width * height * 4; i += 4, j += 3)
{
outputBuffer[j + 0] = inputBuffer[i + 2];
outputBuffer[j + 1] = inputBuffer[i + 1];
outputBuffer[j + 2] = inputBuffer[i + 0];
}
}
}
}