/// <summary>System.Drawing.Bitmap に変換します</summary>
        public static System.Drawing.Bitmap ToDrawingBitmap(this BitmapSource bitmapSource)
        {
            if (bitmapSource.IsInvalid())
            {
                throw new ArgumentException("Invalid Image");
            }

            var bitmap = new System.Drawing.Bitmap(bitmapSource.PixelWidth, bitmapSource.PixelHeight,
                                                   System.Drawing.Imaging.PixelFormat.Format32bppPArgb);

            var bitmapData = bitmap.LockBits(new System.Drawing.Rectangle(System.Drawing.Point.Empty, bitmap.Size),
                                             System.Drawing.Imaging.ImageLockMode.WriteOnly, bitmap.PixelFormat);

            try
            {
                bitmapSource.CopyPixels(Int32Rect.Empty, bitmapData.Scan0,
                                        bitmapData.Height * bitmapData.Stride, bitmapData.Stride);
            }
            finally
            {
                bitmap.UnlockBits(bitmapData);
            }

            return(bitmap);
        }
Esempio n. 2
0
 /// <summary>1PixelのByte数を取得します</summary>
 public static int GetBytesPerPixel(this BitmapSource bitmap)
 {
     if (bitmap.IsInvalid())
     {
         throw new ArgumentException("Invalid Image");
     }
     return(Ceiling(bitmap.Format.BitsPerPixel, 8));
        /// <summary>ToPixelMatrixContainer を作成して返します</summary>
        public static PixelMatrixContainer ToPixelMatrixContainer(this BitmapSource bitmap)
        {
            if (bitmap.IsInvalid())
            {
                throw new ArgumentException("Invalid Image");
            }

            var container = new PixelMatrixContainer(bitmap.PixelWidth, bitmap.PixelHeight);

            container.FullPixels.CopyTo(bitmap);
            return(container);
        }