public static Bitmap AsBitmap(this IPalette palette) { var b = new Bitmap(Size, 1, PixelFormat.Format32bppArgb); var data = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb); var temp = new uint[Palette.Size]; palette.CopyToArray(temp, 0); Marshal.Copy((int[])(object)temp, 0, data.Scan0, Size); b.UnlockBits(data); return b; }
/// <summary> /// Reads the image data from the <see cref="Bitmap"/> and copies it into a /// new three-dimensional array. /// </summary> /// <param name="bmp">The <see cref="Bitmap"/>.</param> /// <returns>The created array.</returns> /// <exception cref="ArgumentNullException"> /// Is thrown if <c>null</c> is given for <paramref name="bmp"/>.</exception> /// <exception cref="ArgumentException"> /// Is thrown if the bitmap has no 24Bit RGB pixel format.</exception> public static byte[, ,] ToRgbArray(this Bitmap bmp) { if (bmp == null) throw new ArgumentNullException("bmp"); if (bmp.PixelFormat != PixelFormat.Format24bppRgb) { throw new ArgumentException("The given bitmap is no 24Bit RGB bitmap.", "bmp"); } var rows = bmp.Height; var cols = bmp.Width; var m = new byte[rows, cols, 3]; bmp.CopyToArray(m); return m; }
/// <summary> /// Convert MathNet.Numerics.LinearAlgebra.Matrix to double[,] /// </summary> /// <param name="v">MathNet.Numerics.LinearAlgebra.Matrix</param> /// <returns>double[,]</returns> public static double[,] ToInterop(this MathNet.Numerics.LinearAlgebra.Matrix m) { return m.CopyToArray(); }
/// <summary> /// Convert MathNet.Numerics.LinearAlgebra.Vector to double[] /// </summary> /// <param name="v">MathNet.Numerics.LinearAlgebra.Vector</param> /// <returns>double[]</returns> public static double[] ToInterop(this MathNet.Numerics.LinearAlgebra.Vector v) { return v.CopyToArray(); }