Esempio n. 1
0
        public static void WritePixels(this WriteableBitmap wbm, BitmapSource bms)
        {
            if (wbm.IsNullOrEmpty() || bms.IsNullOrEmpty())
            {
                return;
            }

            int stride = bms.GetStride();

            byte[] data = new byte[stride * bms.PixelHeight];
            bms.CopyPixels(data, stride, 0);
            wbm.WritePixels(bms.ToInt32Rect(), data, stride, 0);
        }
Esempio n. 2
0
        /// <summary>
        ///    Copies the bitmap pixel data to the given array.
        /// </summary>
        ///
        public static void CopyPixels(this BitmapSource image, Array buffer)
        {
            int stride        = image.GetStride();
            int numberOfBytes = buffer.GetNumberOfBytes();

            Int32Rect r = new Int32Rect(0, 0, image.PixelWidth, image.PixelHeight);

            GCHandle handle = GCHandle.Alloc(buffer, GCHandleType.Pinned);
            IntPtr   ptr    = handle.AddrOfPinnedObject();

            image.CopyPixels(r, buffer: ptr, bufferSize: numberOfBytes, stride: stride);

            handle.Free();
        }
        public static byte[] ToPixelsByteArray(this BitmapSource bms)
        {
            if (bms.IsNullOrEmpty())
            {
                return(null);
            }

            int stride = bms.GetStride();

            byte[] data = new byte[stride * bms.PixelHeight];

            bms.CopyPixels(data, stride, 0);

            return(null);
        }
Esempio n. 4
0
        /* public static bool Fits(this WriteableBitmap wbm, Bitmap bmp)
         * {
         *   if (wbm.ToInt32Rect().)
         *       return true;
         *   else
         *       return false;
         * }*/


        public static WriteableBitmap ToWriteableBitmap(this BitmapSource bms)
        {
            if (bms.IsNullOrEmpty())
            {
                return(null);
            }

            int stride = bms.GetStride();

            byte[] data = bms.ToPixelsByteArray();

            WriteableBitmap wbm = new WriteableBitmap(bms.PixelWidth, bms.PixelHeight, bms.DpiX, bms.DpiY, bms.Format, null);

            wbm.WritePixels(bms.ToInt32Rect(), data, stride, 0);

            return(wbm);
        }