示例#1
0
        public static void FillGrayBitmap(this Bitmap bitmap, IMatrixLayer layer)
        {
            BitmapData bitmapData = bitmap.LockBits(new Rectangle(Point.Empty, bitmap.Size),
                                                    ImageLockMode.WriteOnly,
                                                    PixelFormat.Format8bppIndexed);
            IntPtr intPtr = bitmapData.Scan0;
            int    stride = bitmapData.Stride;
            int    bytes  = Math.Abs(stride) * bitmap.Height;

            byte[]             vs;// = new byte[bytes]; // Bitmap storage
            MatrixLayer <byte> byteLayer = layer.ToByteLayer(false);

            vs = byteLayer.GetStorage(false);
            if (bitmap.Width == stride)
            {
                System.Runtime.InteropServices.Marshal.Copy(vs, 0, intPtr, vs.Length);
            }
            else
            {
                int offsetArr = 0;
                int offsetPtr = 0;
                for (int i = 0; i < bitmap.Height; i++)
                {
                    System.Runtime.InteropServices.Marshal.Copy(vs, offsetArr, (intPtr + offsetPtr), layer.Width);
                    offsetArr += layer.Width;
                    offsetPtr += stride;
                }
            }
            bitmap.UnlockBits(bitmapData);
        }
示例#2
0
        public static void FillGrayBitmap(this Bitmap bitmap, IMatrixLayer layer)
        {
            BitmapData bitmapData = bitmap.LockBits(new Rectangle(Point.Empty, bitmap.Size),
                                                    ImageLockMode.WriteOnly,
                                                    PixelFormat.Format8bppIndexed);
            IntPtr intPtr = bitmapData.Scan0;
            int    stride = bitmapData.Stride;
            int    bytes  = Math.Abs(stride) * bitmap.Height;

            byte[]             vs;// = new byte[bytes]; // Bitmap storage
            MatrixLayer <byte> byteLayer = layer.ToByteLayer(false);

            vs = byteLayer.GetStorage(false);
            System.Runtime.InteropServices.Marshal.Copy(vs, 0, intPtr, bytes);
            bitmap.UnlockBits(bitmapData);
        }
        public static LineSeries CreateLineSeries(IMatrixLayer layer, OxyColor?color = null, string title = null)
        {
            LineSeries ls = new LineSeries();

            if (color.HasValue)
            {
                ls.Color = color.Value;
            }
            if (title != null)
            {
                ls.Title = title;
            }
            MatrixLayer <byte> byteLayer = layer.ToByteLayer(false);

            int[] values = new int[256];
            byteLayer.ForEachPixels(a => values[a]++);
            for (int i = 0; i < 256; i++)
            {
                ls.Points.Add(new DataPoint(i, values[i]));
            }
            return(ls);
        }