Beispiel #1
0
        public static CanvasARGB Clone(CanvasARGB canvas)
        {
            CanvasARGB result = new CanvasARGB(canvas.WidthPixel, canvas.HeightPixel);

            Buffer.BlockCopy(canvas.Data, 0, result.Data, 0, canvas.CountPixels * 4);

            return(result);
        }
Beispiel #2
0
        public static CanvasARGB CreateCanvasFromBitmap(BitmapImage bi)
        {
            CanvasARGB canvas = new CanvasARGB(bi.PixelWidth, bi.PixelHeight);


            bi.CopyPixels(canvas.Data, canvas.Width, 0);
            return(canvas);
        }
Beispiel #3
0
        public static CanvasPixel CreateBitmpaFromCanvas(CanvasARGB canvas)
        {
            CanvasPixel result = new CanvasPixel(canvas.WidthPixel, canvas.HeightPixel);

            Pixel[] dest   = result._data;
            byte[]  source = canvas.Data;

            int di = 0;

            for (int i = 0; i < source.Length; i += 4)
            {
                Pixel tmpP = Pixel.Create(source[i + 3], source[i + 2], source[i + 1], source[i]);
                dest[di] = tmpP;
                di++;
            }

            return(result);
        }
Beispiel #4
0
        public static BitmapSource CreateBitmpaFromCanvas(CanvasARGB canvas)
        {
            if (canvas == null)
            {
                return(null);
            }

            var width       = canvas.WidthPixel;
            var height      = canvas.HeightPixel;
            var dpiX        = 96d;
            var dpiY        = 96d;
            var pixelFormat = PixelFormats.Bgra32;
            var stride      = width * 4;

            var bitmap = BitmapImage.Create(width, height, dpiX, dpiY, pixelFormat, null, canvas.Data, stride);

            return(bitmap);


            //          WriteableBitmap target = new WriteableBitmap(
            //              canvas.WidthPixel,canvas.HeightPixel,96.0,96,PixelFormats.Bgra32,null);
            //          target.

            //source.Format, null);
            //          BitmapSource bs = BitmapSource.Create(canvas.WidthPixel,canvas.HeightPixel,96.0,96,0,)
            //          Bitmap result = new Bitmap(canvas.WidthPixel, canvas.HeightPixel, PixelFormat.Format32bppPArgb);

            //          BitmapData bmdSRC = result.LockBits(new Rectangle(0, 0, result.Width, result.Height), ImageLockMode.ReadOnly,
            //                                      PixelFormat.Format32bppPArgb);
            //          try
            //          {
            //              Marshal.Copy(canvas.Data, 0, bmdSRC.Scan0, canvas.Data.Length);
            //          }
            //          finally
            //          {
            //              result.UnlockBits(bmdSRC);
            //          }

            //          return result;
        }
Beispiel #5
0
        public static CanvasARGB CreateBitmpaFromCanvas(CanvasPixel canvasPixel)
        {
            CanvasARGB result = new CanvasARGB(canvasPixel.Width, canvasPixel.Height);

            byte[]  dest   = result.Data;
            Pixel[] source = canvasPixel.Data;

            int di = 0;

            for (int i = 0; i < source.Length; i++)
            {
                Pixel p = source[i];

                dest[di]     = p.B0;
                dest[di + 1] = p.B1;
                dest[di + 2] = p.B2;
                dest[di + 3] = p.B3;

                di += 4;
            }

            return(result);
        }